[api][plan][integrations][java][python] Apply an agent output schema natively on the final response #1215
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1215"
general
weight: 0.35
weiqingy
Linked issue: #912
Purpose of change
When an agent asks for structured output and its chat model can enforce a schema natively, the final answer now comes from a provider call carrying the schema, so the provider enforces the format rather than the prompt. This completes #280: providers could apply a schema, but the runtime never handed one over.
Nothing changes when the schema does not resolve to native; under the default
AUTOthat covers every unlisted model and everyRowTypeInfoschema.Runtime flow
1.
ReActAgentasks the chat model setup whether the schema will travel natively. If yes, the loop prompt describes the schema's fields without asking for JSON; otherwise it keeps the JSON instruction.2. The chat model action asks the same once per request, before retrying.
3. The tool-calling loop runs as today.
4. On a native final answer (no tool calls), the same attempt makes one more call with the schema and no tools: a user message holding a conversion instruction and the answer's text. Its response is parsed.
Key decisions
tool_choice,tool_choice_optionandparallel_tool_calls, also insideadditional_kwargs.NATIVEon an unlisted model keeps the schema.Behavioral Semantics
Interaction decisions
| Strategy | Connection's answer | Result |
|---|---|---|
|
PROMPT| any | Prompt path ||
AUTO| native recommended | Native: extra call, field instruction ||
AUTO| feasible, or infeasible | Prompt path ||
NATIVE| native recommended, or feasible | Native ||
NATIVE| infeasible (e.g.RowTypeInfo) | Fails before any model call || any | setup bridged to the other language | Prompt path;
NATIVEfails before any model call || any | no connection bound, check not overridden | Fails before any model call, naming
open()|Behavioral contracts
1. The extra call happens only when the strategy resolves to native and the answer has no tool calls.
2. Its only message is a user message: the conversion instruction, then the answer's text.
3. It carries the schema, binds no tools, and omits the tool-choice parameters.
4. Its response is the one parsed.
5. A chat call given
tools(Java 4-arg, Pythontools=) skips the bound prompt, skill-discovery message and bound tools; otherwise chat prepares the request as before.6. Tool-choice parameters are omitted whenever a call carries a schema and binds no tools; the native check sees the same parameters.
7. For a non-null schema, the native check requires a bound connection.
8. An unhonorable
NATIVEfails with a message naming the connection and the schema.9.
ReActAgentuses the field instruction only on a native answer; any other answer or a failure keeps the JSON instruction.10. A recovered run replays both calls from the durable record without calling the model.
Failure behavior
ChatResponseEventis sent.ReActAgentcheck.Tests
<details><summary>Tests per contract</summary>
| Contract | Pinned by |
|---|---|
| 1 |
ChatModelActionRetryTest;test_chat_model_action_retry.py|| 2, 3 |
nativeSchemaConvertsTheFinalAnswerInASeparateSchemaCarryingCall;test_finalization_call_carries_answer_directive_and_schema|| 4 | parse-from-final tests in both languages |
| 5 |
BaseChatModelTest,test_chat_model_base.py; bridge refusals inPythonChatModelSetupTest,test_java_chat_model.py|| 6 | tool-param tests in both base test files |
| 7 |
testWillApplyNativeStructuredOutputRequiresOpen;test_will_apply_native_structured_output_requires_open|| 8 | strategy x answer grids in both base test files; bridge tests |
| 9 |
ReActAgentTest;test_react_agent_schema_instruction.py|| 10 |
ChatModelInvokerTestreplay;test_flink_runner_context_reconcilable.py|</details>
End to end against Ollama (
qwen3:1.7b),ReActAgentTest#testReActAgentNativeStructuredOutputandtest_react_agent_native_structured_output_on_remote_runnerrun the ReAct tool loop with a POJO /BaseModelschema underAUTO. A recording connection checks that the loop requests carried the tools and no schema, that the last request carried the schema and no tools, and that the model called a tool; the typed result is checked too. Forcing the prompt strategy makes both tests fail.Every commit was mutation-tested, and all non-equivalent mutants were killed.
Not verified:
Known limit: Java POJO instructions carry no field descriptions, since Jackson's schema generator drops them (as on the JSON path).
API
BaseChatModelSetup:willApplyNativeStructuredOutputandchat(messages, tools, modelParams, outputSchema)(Java);will_apply_native_structured_outputand keyword-onlytools/output_schemaonchat(Python;prompt_argswithtoolsraises). Users configurestructured_output_strategyinstead.connection.chat(..., outputSchema)callers: an unlisted model now gets the native parameter, so Anthropic drops its JSON prefill, Azure and DashScope reject a caller-suppliedresponse_format, and Python raisesTypeErrorfor a schema Pydantic cannot render.ReActAgentwith a schema registers one more prompt resource; an older plan gets no instruction on the native path.Documentation
doc-neededdoc-not-neededdoc-includedUser documentation for structured output across providers follows in a separate PR.
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code 2.1.294 and GitHub Copilot CLI 1.0.95 (Claude Opus 5.5)