Claude API · Tools and structured output
Constrain output with a JSON Schema
Use output_config.format when you want raw JSON that follows your schema.
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=16000,
messages=[{"role": "user", "content": "Extract the name from: John Smith wants the Enterprise plan."}],
output_config={"format": {"type": "json_schema", "schema": {
"type": "object",
"properties": {"name": {"type": "string"}},
"required": ["name"],
"additionalProperties": False,
}}},
)
Official Claude API documentation
More tools and structured output commands
- Let the SDK run the tool loop
- Define a tool by hand
- Return a tool result
- Guarantee valid tool input
- Get a validated Python object back
All tools and structured output commands · Claude API cheatsheet