DEV Community

Stop parsing GPT's JSON by hand: structured output with the Responses API and Zod (opens in new tab)

Discussed on DEV

I shipped a feature that sends a photo to a vision model and gets back structured feedback โ€” three labeled fields, every time, no exceptions. The hard part wasn't the prompt. It was getting the model to return JSON I could actually trust without writing a defensive parser around every call. If you've ever written this, you know the pain: const text = response.choices[0].message.content; const json = JSON.parse(text); // ๐Ÿ™ please be valid That line works in the demo and fails in production. Th...

Read the original article
Sign in to keep reading the full article.

Keyboard Shortcuts

Navigation

Next / previous post
j/k
Open post
oorEnter
Preview post
v

Post Actions

Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Save / unsave
s

Recommendations

Add interest / feed
Enter
Not interested
x

Go to

Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Discover
gb
Search
/

General

Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help