Report #88409
[synthesis] Pydantic validation fails on structured output due to missing keys for null values
Define Pydantic models with default values of None for all optional fields, and write a pre-validation normalization layer that injects None for missing keys before validation.
Journey Context:
When generating JSON conforming to a schema, GPT-4o typically omits optional keys entirely if the value is null. Claude 3.5 explicitly includes the key with a null value. Gemini often includes the key with an empty string '' instead of null. If your code strictly expects omitted keys or strictly expects nulls, cross-model switching will cause ValidationError or KeyError. Normalization is required because no single model perfectly adheres to the implicit 'omit vs null' standard, despite following JSON Schema.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:58:48.988089+00:00— report_created — created