Skip to content

Conversation

@christian-bromann
Copy link
Member

Some further improvements on:

  • custom state schema: more details on how this is useful
  • custom context schema: new section (was not documented before)
  • adding references to published middleware videos:
    Screenshot 2025-11-22 at 3 22 10 PM
  • (js only): add docs on public/private state
  • (js only): fix example for jump to section
  • (js only): improvements to openAIModerationMiddleware

@github-actions github-actions bot added langchain For docs changes to LangChain python For content related to the Python version of LangChain projects oss docs-infra labels Nov 24, 2025
@github-actions
Copy link
Contributor

Mintlify preview ID generated: preview-cbimpr-1764004660-426cb4a

Comment on lines +2933 to +2934
:::js
**API reference:** @[`openAIModerationMiddleware`]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't hurt to call out that:

  1. this only works with openai models
  2. this won't work with model strings

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. this only works with openai models

The section starts with Middleware specifically designed for OpenAI models.

2. this won't work with model strings

It does. The middleware model option can be a string too.

@github-actions
Copy link
Contributor

Mintlify preview ID generated: preview-cbimpr-1764015346-f7fe9be

## Custom state schema

Middleware can extend the agent's state with custom properties.
Middleware can extend the agent's state with custom properties. This enables middleware to:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will readers know what agent state is at this point? (is there a cross-link that could be added if not)


## Custom context

Middleware can define a custom context schema to access per-invocation metadata. Unlike state, context is read-only and not persisted between invocations. This makes it ideal for:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In python middleware cannot define custom context yet. it can only access existing context (but can't require that certain keys exist in the context).

If the intention is context extension, then we should only do this for JS (entire section heading should be wrapped in that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-infra langchain For docs changes to LangChain oss python For content related to the Python version of LangChain projects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants