What is structured output / JSON mode? How do you enforce schema compliance?medium
Answer
Structured output forces the model to return valid JSON matching a schema.
Explanation
Structured output forces the model to return valid JSON matching a schema. Approaches: (1) Prompt instruction + few-shot. (2) JSON mode in API (guarantees valid JSON, not schema). (3) Tool use / function calling — model must produce arguments matching the tool's JSON schema. (4) Pydantic parsing with retry loop: if parse fails, send error back with correction instruction. Layer all three in production.
Follow-upCan you give a production example?