RSS Amplifier

AI Interview Prep · Aug 8, 2026

LLM Inference Interview Questions #10 - The JSON Serialization Trap

0
Sign in to vote or save

Hao Hoang · AI Interview Prep

You’re in a Senior AI Engineer interview at Anthropic and the interviewer asks:

“Your coding agent keeps failing on multi-line Python, escaped quotes, mangled indentation. A teammate says just use a stronger model. What’s the real fix?”

Most candidates say: “Add a JSON repair step and retry the call.”

Wrong instinct. You just built a band-aid around a design flaw.

Here’s what’s actually happening.

This isn’t a reasoning failure. It’s a serialization failure. The model knows the code. It fails at the transport layer.

JSON demands every " becomes \". Every newline becomes \n. Every backslash doubles. Your model isn’t writing Python anymore, it’s writing an encoded version of Python, one escape token at a time.

You’re asking a chef to pass you a soufflé through a letterbox.

Three things break:

a) Out-of-distribution encoding. Pretraining saw billions of lines of raw Python. It saw far less \"\"\"Docstring.\"\"\"\n return x. You moved the payload off-manifold.

b) Silent corruption. A dropped backslash doesn’t throw. The JSON parses. The patch applies. The indentation is wrong, and CI finds out 40 minutes later.

c) Escape tax. Escaped code inflates token count, and every escape is another chance to break.

The fix, in priority order:

Read the original on aiinterviewprep.substack.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.