Skip to content

Commit d708626

Browse files
abossardCopilot
andcommitted
Enable OpenAI JSON mode for guaranteed valid JSON output
Adds response_format: {type: 'json_object'} to the ChatOpenAI constructor via model_kwargs. This is a model-level setting that constrains token generation to valid JSON — no extra LLM call, no post-processing, just guaranteed JSON from every response. This is different from LangGraph's response_format parameter (which adds a separate LLM call). This is OpenAI's native JSON mode applied at the API level during the same call. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b96e048 commit d708626

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

backend/agent_builder/engine/react_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def build_llm(
4141
"api_key": api_key,
4242
"base_url": base_url or None,
4343
"temperature": temperature,
44+
"model_kwargs": {"response_format": {"type": "json_object"}},
4445
}
4546
if max_tokens > 0:
4647
kwargs["max_tokens"] = max_tokens

0 commit comments

Comments
 (0)