You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just a thought, but it may be worthwhile to add a note on structured outputs (docs & codebase) in that if your struct tags have omitempty that the openai-go api will silently ignore them and the model will not populate that field.
Chased my tail on this one for a while. Is there a way to specify to not ignore omitempty tags?
The current structured-output example now contains an omitempty warning. I checked its actual GenerateSchema helper offline with the examples module's pinned invopop/jsonschema v0.14.0 (Go 1.27.1 darwin/arm64):
Field tags
property exists in schema
in required array
json:"label"
yes
yes
json:"label,omitempty"
yes
no
json:"label,omitzero"
yes
no
json:"label,omitempty" jsonschema:"required"
yes
yes
All four assertions passed. In this schema-generation path, omitempty changes requiredness; it does not remove the property from the schema. An explicit jsonschema:"required" overrides that inferred optionality with this pinned reflector version, so it is an option when the same Go type also needs omitempty for ordinary JSON marshaling. Removing omitempty is the simpler option if that dual use is unnecessary.
I also checked json.Marshal of a zero-valued struct with both omitempty and jsonschema:required: it still emits an empty object. The schema tag affects reflection, not encoding/json's serialization rules. Keep those two behaviors distinct when using a type for both request marshaling and schema generation.
# from examples module
go test -mod=readonly -run TestDharmaRequiredTags -v -count=1 -timeout=30s ./structured-outputs
Only the helper was exercised; example main was not run, network was denied and no model/API request occurred. This confirms schema properties/requiredness for the pinned dependency, not server acceptance, field generation by a model, all nested/tag combinations, or other reflector versions.
Activity
jnohclee-rgb commentedon Oct 6, 2026
The current structured-output example now contains an omitempty warning. I checked its actual GenerateSchema helper offline with the examples module's pinned invopop/jsonschema v0.14.0 (Go 1.27.1 darwin/arm64):
All four assertions passed. In this schema-generation path, omitempty changes requiredness; it does not remove the property from the schema. An explicit
jsonschema:"required"overrides that inferred optionality with this pinned reflector version, so it is an option when the same Go type also needs omitempty for ordinary JSON marshaling. Removing omitempty is the simpler option if that dual use is unnecessary.I also checked
json.Marshalof a zero-valued struct with both omitempty and jsonschema:required: it still emits an empty object. The schema tag affects reflection, not encoding/json's serialization rules. Keep those two behaviors distinct when using a type for both request marshaling and schema generation.Only the helper was exercised; example main was not run, network was denied and no model/API request occurred. This confirms schema properties/requiredness for the pinned dependency, not server acceptance, field generation by a model, all nested/tag combinations, or other reflector versions.