tool_call envelope, and your application is responsible for executing the tool and continuing the loop. That is different from OpenAI-style built-in tool calling, where the API returns tool call objects in its own response format. Without a strict output contract, the model might mix fields from both branches, invent new action types, or omit the information your executor needs to dispatch. A oneOf schema with a const discriminator eliminates this: the model picks exactly one branch, emits exactly the right fields, and your orchestration code can dispatch without parsing heuristics.
Use case
You run an agent that can either call a tool or return a final answer. You want one schema that covers both outcomes, with a confidence score on every action for routing and observability.Schema pattern
Prompt snippet
Example outputs
Tool call:Why this works
oneOf enforces mutual exclusivity: the model must produce either a tool_call or a final_answer, never a hybrid. Your executor reads kind, dispatches to the right handler, and never needs to guess what the model intended.
The const discriminator on kind removes ambiguity. Without it, both branches might structurally overlap (both could have a string field), and validation alone couldn’t tell them apart.
Confidence appears in both branches, so your orchestration layer can apply the same routing logic regardless of action type, for example, escalating to a human when confidence drops below a threshold.