How to Make Anthropic’s Claude Models Consistently Generate Valid JSON

Practicus AI
Level Up Coding
Published in
5 min readDec 27, 2023

--

Image by Alexandra_Koch from Pixabay

OpenAI’s GPT models are known to be quite good at consistently outputting valid JSON, especially when using the new JSON mode for GPT-4 Turbo.

Unfortunately, the same can’t be said for Anthropic’s Claude models which frequently make mistakes in attempting to output JSON. The most common errors tend to be:

--

--