Urgent.News

What's breaking now, across thousands of outlets.

AI

Stop Telling Your AI What Format You Want. Start Writing It.

You ask the model for a JSON object. Your parser gets this: Certainly! Here's the JSON you asked for: {"severity": "high", "summary": "Login fails after password reset"} Let me know if you'd like me to adjust anything! json.loads() throws. Your pipeline stops. And the prompt did say "respond with JSON only." If you build anything on top of an LLM, you've hit this. The usual reaction is to add…

The wire material discusses a common issue when using large language models (LLMs) like ChatGPT for generating structured output like JSON objects. The problem arises when users ask the model to respond exclusively in a specific format, such as JSON, while also providing instructions on the desired format. The model tends to ignore the explicit format request and instead adheres to its default, helpful, and polite style by adding introductory sentences or concluding remarks.

The author argues that the source of the problem lies in the way LLMs are trained - they are designed to sound helpful and polite, which leads to the inclusion of generic phrases like "Certainly!" or "Let me know if...". When these phrases are used to convey a format instruction, the model is more likely to deviate from the desired format, especially as prompts become longer or the interaction goes on for multiple messages.

The solution proposed is to instead "seed" the desired format directly into the model's response, rather than issuing it as a rule or instruction. This involves providing the model with the exact beginning of the desired format, such as "{ severity: ", and asking it to continue. By doing so, the model has no choice but to adhere to the specified structure, as any deviation would disrupt the continuity of the generated output.

The author presents three key fixes to mitigate this issue:

1. Seed the format: Instead of describing the format, the author suggests giving the model the first characters of the desired format and asking it to continue from there. This prevents the model from inserting any extraneous introductory sentences or closing remarks. Examples are provided for different types of structured output, such as JSON, numbered lists, verdicts, and tables.

2. Utilize API features: If the model is being called through an API rather than a chat interface, the author recommends checking if the API supports structured output or JSON mode. Additionally, some APIs allow you to pre-fill the model's response with the opening of the desired format, ensuring that the model continues from this point without deviation.

3. Implement validation: Regardless of the method used, the author emphasizes the importance of validating the generated output programmatically to ensure it conforms to the specified format. This is crucial since models are probabilistic and cannot be completely trusted to adhere to the format strictly.

The author concludes by encouraging readers to test the proposed fixes on their own prompts and share their experiences. They also offer a free 7-page briefing with before/after comparisons, a ban list of ineffective phrases, and a copy-paste master template for implementing the recommended fixes.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

Stop Using LLMs Like Search Engines

Most devs use modern language models wrong. They open a chat window, paste an error stack trace, and wait for a magic snippet. When it works, they celebrate.

  • LLMs are spatial compressors of human text, not search engines.
  • Treating LLMs like APIs requires explicit architectural constraints and data types.
  • Building domain-specific wrappers with internal documentation improves results.

Semantic Caching and Live Internet Search: Tools That Let AI Cache Answers to Save Money, and Pull Data From the Web When It Needs To

Say you open the logs of your chat system and they are full of questions like these: "How do I change my password?" "Forgot my password, what do I do?" "Where do I reset my password?" All three mean…

  • Semantic caching saves costs by remembering answers to similar questions.
  • Live internet search provides real-time data when needed.
  • Two methods work together with a sorting step to determine appropriate approach.

More from Friday 30 October →