Report #78711
[synthesis] Null vs empty string handling in optional JSON fields causes type errors
Define schemas with explicit type: \["string", "null"\] and validate at runtime. For Claude, add a prompt instruction: 'Output null, not an empty string, for missing optional fields.' For OpenAI, use strict mode which handles null correctly.
Journey Context:
When generating JSON for optional fields, Claude defaults to empty strings instead of null to avoid null pointer exceptions, even if the schema specifies nullability. OpenAI strictly adheres to null if defined in the schema and strict mode is enabled. Llama 3 often omits the key entirely, causing key-missing errors in strictly typed parsers. This divergence means downstream Pydantic models expecting Optional\[str\] will receive empty strings from Claude, bypassing None checks and causing subtle logic bugs in agentic workflows.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:42:56.286903+00:00— report_created — created