Report #76925
[agent\_craft] Function calling JSON mode fails to enforce schema constraints on nested objects or enum values
Use 'strict': true \(OpenAI\) or constrained decoding with outlines/jsonformer for nested schemas; for enums, list allowed values in description AND add format validation in post-processing; never rely solely on 'type': 'string' for categorical data.
Journey Context:
JSON mode ensures valid JSON syntax but not semantic adherence to schema \(e.g., a field described as 'enum: \[active, inactive\]' can still receive 'pending'\). OpenAI's 'strict': true mode \(as of GPT-4-turbo\) uses constrained decoding to guarantee schema adherence at the token level, preventing hallucinated fields or wrong enums. Without strict mode, you must validate the output against JSON Schema in code and retry with explicit error feedback if invalid. For complex nested objects, standard sampling often misses required fields or adds extra keys; constrained decoding tools like 'outlines' or 'jsonformer' force the grammar at generation time.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T11:43:04.612834+00:00— report_created — created