tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Prompt Engineering > Output Format Control - Tables, Lists, and Markdown in Prompts

Output Format Control - Tables, Lists, and Markdown in Prompts

Author: Venkata Sudhakar

Controlling the output format of LLM responses is essential for building reliable systems at ShopMax India. When Claude generates a product comparison, the downstream code expects a specific structure - a JSON object, a pipe-delimited table, or a numbered list - not free-form prose. Explicit format instructions in the prompt prevent costly parsing failures and ensure the output integrates cleanly with the rest of the pipeline.

Format control techniques range from simple ("respond only with JSON") to detailed (providing an exact template with field names and example values). The most reliable approaches show the model an exact example of the desired output format, use phrases like "your response must match this structure exactly", and validate the output before using it. For structured data, JSON with a schema is more robust than markdown tables, which LLMs occasionally misalign.

The example below shows ShopMax India requesting product comparison output in three different formats - JSON, markdown table, and numbered list - for the same input, demonstrating how format instructions change the response structure.


It gives the following output,

Format: json
{"winner": "Samsung", "reason": "Better value with 120Hz refresh rate at Rs 18000 less", "scores": {"samsung": 8, "sony": 7}}
JSON valid - winner: Samsung

Format: table
| Feature        | Samsung          | Sony             |
|----------------|------------------|------------------|
| Price          | Rs 54,999        | Rs 72,999        |
| Resolution     | 4K UHD           | 4K UHD           |
| Refresh Rate   | 120Hz            | 60Hz             |
| Value for Money| Excellent        | Good             |

Format: list
1. Samsung is Rs 18,000 cheaper at Rs 54,999 vs Sony at Rs 72,999.
2. Samsung offers 120Hz refresh rate vs Sony 60Hz, better for gaming.
3. Sony OLED has superior contrast and black levels for movie watching.
4. Samsung offers better overall value for most Indian buyers.

At ShopMax India, always validate structured outputs before downstream use - even with strict format instructions, LLMs occasionally add preamble text before the JSON. Use a regex to extract the JSON block if needed, or add a post-processing step that strips non-JSON text. For high-reliability APIs, use Anthropic's tool_use feature to force structured JSON output rather than relying on prompt instructions alone - it enforces the schema at the API level, not just as a hint.


 
  


  
bl  br