Skip to content

feat(openrouter,fireworks): support response_format on invoke and bind_tools - #40390

Draft
Mason Daugherty (mdrxy) wants to merge 1 commit into
masterfrom
mdrxy/core/response-format-provider-strategy
Draft

Mason Daugherty (mdrxy) wants to merge 1 commit into
masterfrom
mdrxy/core/response-format-provider-strategy

Conversation

@mdrxy

Copy link
Copy Markdown
Member

ChatOpenRouter and ChatFireworks now accept response_format as a Pydantic model class, TypedDict class, dataclass, JSON schema dict, or an OpenAI-style {"type": "json_schema", "json_schema": {...}} envelope — on both invoke(..., response_format=...) and bind_tools(response_format=...).

  • Why: create_agent's ProviderStrategy binds this envelope shape, so create_agent(response_format=MySchema) silently failed to enforce structured output on OpenRouter and Fireworks. Direct schema support also simplifies structured output flows (e.g. deepagents) that previously had to route through with_structured_output.
  • The converters normalize any supported schema shape into the provider's json_schema envelope and pass existing json_object/text envelopes through untouched. strict is forwarded when explicitly provided.
  • ChatOpenAI, ChatAnthropic (via output_config.format), and ChatOllama (via format) already handled these shapes; this brings OpenRouter and Fireworks to parity.

Release note

langchain-openrouter and langchain-fireworks chat models now support response_format (Pydantic model, TypedDict, dataclass, JSON schema, or OpenAI-style json_schema envelope) when passed directly to invoke/bind_tools, enabling native structured output through create_agent's ProviderStrategy.

AI-agent involvement: this contribution was prepared collaboratively with Open SWE; a human reviewer should verify the schema-conversion edge cases.

Made by Open SWE · openai:gpt-5.6-sol (high)

@github-actions github-actions Bot added feature For PRs that implement a new feature; NOT A FEATURE REQUEST fireworks `langchain-fireworks` package issues & PRs integration PR made that is related to a provider partner package integration internal openrouter `langchain-openrouter` package issues & PRs size: M 200-499 LOC labels Sep 10, 2026
…ind_tools

`ChatOpenRouter` and `ChatFireworks` accept `response_format` as a
Pydantic model class, `TypedDict` class, dataclass, JSON schema dict, or
an OpenAI-style `json_schema` envelope — the shape `ProviderStrategy`
emits for `create_agent(response_format=...)`.

Previously these schemas only worked via `with_structured_output`; passing
them through `invoke(..., response_format=...)` or
`bind_tools(response_format=...)` forwarded the raw class object to the
API, causing serialization errors or API rejections.

Co-authored-by: open-swe[bot] <[email protected]>
@open-swe
open-swe Bot force-pushed the mdrxy/core/response-format-provider-strategy branch from e8568ed to 6b766fc Compare September 10, 2026 21:16

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace

Comment on lines +177 to +179
if envelope_type in ("json_object", "json_schema", "text"):
# Already a `response_format` the API understands
return schema

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Preserve Fireworks grammar response format support

Fireworks supports response_format={"type": "grammar", "grammar": 'root ::= "yes" | "no"'} (provider documentation). Previously this was forwarded to the client, but the new normalization excludes grammar from the passthrough branch and falls through to convert_to_json_schema, which raises ValueError because this dictionary has no function name or schema title. This breaks existing grammar-mode calls in all four generation paths, including streaming and async. Preserve the grammar envelope and add a regression test.

(Refers to lines 177-179)


Your feedback helps Open SWE learn. React with 👍 or 👎 to tell us if this review comment was useful.

Suggested change
if envelope_type in ("json_object", "json_schema", "text"):
# Already a `response_format` the API understands
return schema
if envelope_type in ("json_object", "json_schema", "text", "grammar"):
# Already a `response_format` the API understands
return schema

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

Labels

feature For PRs that implement a new feature; NOT A FEATURE REQUEST fireworks `langchain-fireworks` package issues & PRs integration PR made that is related to a provider partner package integration internal openrouter `langchain-openrouter` package issues & PRs size: M 200-499 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant