Skip to content

< CurriculumModel APIs · 6 of 46 ·01 · Level 01, LLM APIs

Get the JSON Out of a Model's Reply

easy · implement · LLM Fundamentals

You asked the model for JSON and it sent back this:

```json
{"name": "Sarah", "issue": "can't log in"}
```

json.loads raises on that. Sometimes the model wraps the JSON in a markdown fence, sometimes it adds a sentence first, sometimes it returns clean JSON. You do not get to choose.

Write parse_model_json(reply):

  • Return the JSON object from the reply, as a dict.
  • Return None if there isn't one.