feat(openrouter,fireworks): support response_format on invoke and bind_tools - #40390
Draft
Mason Daugherty (mdrxy) wants to merge 1 commit into
Draft
Mason Daugherty (mdrxy) wants to merge 1 commit into
Mason Daugherty (mdrxy) wants to merge 1 commit into
Conversation
…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
Bot
force-pushed
the
mdrxy/core/response-format-provider-strategy
branch
from
September 10, 2026 21:16
e8568ed to
6b766fc
Compare
Comment on lines
+177
to
+179
| if envelope_type in ("json_object", "json_schema", "text"): | ||
| # Already a `response_format` the API understands | ||
| return schema |
Contributor
There was a problem hiding this comment.
🟡 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ChatOpenRouterandChatFireworksnow acceptresponse_formatas a Pydantic model class,TypedDictclass, dataclass, JSON schema dict, or an OpenAI-style{"type": "json_schema", "json_schema": {...}}envelope — on bothinvoke(..., response_format=...)andbind_tools(response_format=...).create_agent'sProviderStrategybinds this envelope shape, socreate_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 throughwith_structured_output.json_schemaenvelope and pass existingjson_object/textenvelopes through untouched.strictis forwarded when explicitly provided.ChatOpenAI,ChatAnthropic(viaoutput_config.format), andChatOllama(viaformat) already handled these shapes; this brings OpenRouter and Fireworks to parity.Release note
langchain-openrouterandlangchain-fireworkschat models now supportresponse_format(Pydantic model,TypedDict, dataclass, JSON schema, or OpenAI-stylejson_schemaenvelope) when passed directly toinvoke/bind_tools, enabling native structured output throughcreate_agent'sProviderStrategy.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)