A practical guide comparing three approaches for getting structured, machine-readable outputs from LLMs: JSON Mode, Function Calling, and OpenAI's Structured Outputs. JSON Mode guarantees valid JSON but not a specific schema. Function Calling lets you define an explicit schema and is the foundation of agentic workflows where the model selects and invokes tools. Structured Outputs adds constrained decoding to enforce the schema at the token generation level, eliminating deviations. The post includes Python code examples for each approach and a decision framework: use JSON Mode for quick, flexible needs; Function Calling for agentic action selection; and Structured Outputs for production pipelines requiring strict consistency.

12m read timeFrom towardsdatascience.com
Post cover image
Table of contents
1. What is JSON Mode?2. What is Function Calling?Bonus: A little more on Function Calling3. What about Structured Outputs?But aren’t all these the same thing?On my mind
352 Impressions2 Comments