Skip to content

Talk to code, not to people

Getting output your program can trust.

In an agent, the model's output goes to code, not a person. Code needs an exact format.

Extract the student's details as JSON with name, college and year: 'hey this is Rohan from VIT Pune, 3rd year CSE, want to start DSA'

What the model returned

```json
{
  "name": "Rohan",
  "college": "VIT Pune",
  "year": "3rd year"
}
```

Your code: JSON.parse(reply)

Crashed

SyntaxError: Unexpected token '`', "```json { "... is not valid JSON

Real data from gemini-3.5-flash-lite, 2026-10-16

Asked politely, the model wrapped its JSON in a Markdown fence and json.loads failed. Given a schema, it returned clean JSON, and “3rd year” became the number 3.

Your code parses the model's answer. What's the most reliable way to get valid JSON?