A malformed model response crashes the route
Locate the failed assumption, reproduce it, then repair the cause.
What actually caused it
A model response can look finished and still fail the contract the route promised the client. The AI-native lesson why-ai-code-looks-right-and-isnt names the same gap: looking right is not the same as matching a rule you own. On the server the failure is a body. choices is missing, content is empty, or the text is not the shape you agreed to send on. Code that reads payload.choices[0].message.content throws, and the framework turns that into a 500 whose body is a stack. Callers see a crash. They do not see a refusal you wrote. Forwarding the provider because it parsed ships that shape, including a blank string, straight to the user. A shape check is not a fact check. It is the minimum that stops the crash and stops you from handing over a body you did not .
Minimal reproduction
Before
const payload = { note: 'looks finished' };
res.json({ summary: payload.choices[0].message.content });
The failure is silent or crashes.
The fix
Put the contract in one that returns the summary string or . Null covers a missing list, a missing message, and a blank string. The route sends 502 and a stable error when the function returns null, and it sends the string only when the function returns one. Do not pass the raw provider through. Do not catch the TypeError and replace it with 200. After the shape passes, decide whether your product still needs a factual check. A sentence can have the right field and still be wrong. That second check is the contract the AI-native lesson describes. The shape check only keeps the wrong shape off the wire.
After
const summary = summaryFrom(payload);
if (!summary) return res.status(502).json({ error: 'The model response did not match the summary contract.' });
res.json({ summary: summary });
The check happens before the damage.