Structured Output
PromptingDefinition
Guaranteed formatted output (typically JSON) from Claude. The most reliable method is to define a schema as a tool and set tool_choice to force its use — Claude's tool_use blocks are always valid JSON. Alternatively, use --output-format json with --json-schema in Claude Code CLI.
Example Usage
Define a JSON schema as a tool definition and set tool_choice: {type: 'tool', name: 'output_schema'} to guarantee parseable output.
Related Concepts
Structured Output via Tool Use & JSON Schemas
Prompt EngineeringTool use with JSON schemas eliminates syntax errors but not semantic errors
tool_choice Options & Forced Tool Selection
Prompt Engineeringtool_choice: 'auto' may return text; 'any' guarantees a tool call; forced selection guarantees a specific tool