One thing I've been dealing with on the JS/TS side — if you're not using Python and Pydantic, Zod + the OpenAI SDK's zodResponseFormat helper is a game changer for this exact problem. You define your schema once in Zod, pass it as the response format, and get typed, validated output back. No more writing JSON schemas by hand.
The part about prompt injection affecting structured output is something I don't see enough people talk about. Even with json_schema mode, the content of the values can still be manipulated by injection — the schema just ensures the shape is right. So you still need to sanitize/validate the actual values in your business logic.
Curious — have you run into issues with the strict schema mode and optional fields? I found that handling nullable vs missing fields gets tricky when additionalProperties: false is set.
Thanks for sharing this — the Zod + OpenAI SDK approach sounds really useful for the JS/TS side.
I’m currently exploring the JS/TS ecosystem around this and planning a small project to experiment with structured outputs more deeply. I haven’t hit the strict schema + optional field edge cases yet, but I’ll definitely watch for that as I build it.
Really appreciate you pointing that out — I’ll share what I learn once I’ve had a chance to experiment with it more.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
One thing I've been dealing with on the JS/TS side — if you're not using Python and Pydantic, Zod + the OpenAI SDK's
zodResponseFormathelper is a game changer for this exact problem. You define your schema once in Zod, pass it as the response format, and get typed, validated output back. No more writing JSON schemas by hand.The part about prompt injection affecting structured output is something I don't see enough people talk about. Even with
json_schemamode, the content of the values can still be manipulated by injection — the schema just ensures the shape is right. So you still need to sanitize/validate the actual values in your business logic.Curious — have you run into issues with the strict schema mode and optional fields? I found that handling nullable vs missing fields gets tricky when
additionalProperties: falseis set.Thanks for sharing this — the Zod + OpenAI SDK approach sounds really useful for the JS/TS side.
I’m currently exploring the JS/TS ecosystem around this and planning a small project to experiment with structured outputs more deeply. I haven’t hit the strict schema + optional field edge cases yet, but I’ll definitely watch for that as I build it.
Really appreciate you pointing that out — I’ll share what I learn once I’ve had a chance to experiment with it more.