Structured Output: JSON / Function Calling
In apps, machine-processable structured output, not free text, is essential. Use JSON output or Function/Tool Calling.
Means
- Schema-specified JSON output: define types and required fields and have it return them
- Function/Tool Calling: have the model output "the function and arguments to call"; execution is your own
Hardening Points
- Schema-validate output: reject broken JSON, retry/fallback
- Instruct against extra preamble/code fences
- Fix enum values (don't allow free-form)
- Always validate arguments before function execution (don't trust the model)
Caution
- "Return as JSON" alone breaks. Design presuming validation + retry
- Function Calling is "receive intent," not "delegate execution." People/code judge whether to execute
Key Point
Structured output is "the glue to embed an LLM in a program." Don't trust without validation—that's the premise of stable operation.