Cookbooks
How to structure LLM output with Anthropic models
What is structured output?
Structured Outputs is a feature that ensures the model will always generate responses that adhere to your supplied JSON Schema, so you don’t need to worry about the model omitting a required key, or hallucinating an invalid enum value.
How to use structured output with Anthropic models
We currently only support structured output with Anthropic models only when you use OpenAI SDK. Which means to get structured output from Anthropic models, you should call anthropic models using the OpenAI SDK client to our endpoint.
Example code
You can simply add response_format={json_schema: {YOUR_JSON_SCHEMA}}
to your request. Under the hood, we create a function that asks Anthropic model to response in JSON format.