Controlling LLM Output Format: JSON, Markdown, Tables, and Code

Learn to reliably get structured output from LLMs — JSON, markdown, tables, and code — using explicit format instructions.

🔰 beginner
⏱️ 75 minutes
👤 SuperML Team

· AI Engineering · 1 min read

🎯 What You'll Learn

  • Understand and apply the core concepts covered in this lesson

Why Output Format Matters

Without format instructions, LLMs produce inconsistent output. Sometimes JSON, sometimes prose, sometimes a mix. For downstream processing, you need reliability.

Getting JSON

Be explicit about the schema:

Extract the key information from this job posting. Return ONLY valid JSON — no explanation, no markdown wrapper.

Schema:
{
  "title": "string",
  "company": "string",
  "salary_min": "number or null",
  "salary_max": "number or null",
  "remote": "boolean",
  "required_skills": ["string"]
}

Posting: [TEXT]

Getting Markdown

Write a comparison of PostgreSQL vs MongoDB for a high-traffic API backend.
Format as a markdown document with:
- An H2 heading for each database
- A "Best for" subsection under each
- A final "Recommendation" section

Getting Tables

Compare the top 3 JavaScript frameworks (React, Vue, Svelte) across these dimensions: 
learning curve, performance, ecosystem size, and best use case.
Return as a markdown table.

Getting Code

Write a Python function that parses a CSV file and returns a list of dicts.
Requirements:
- Type hints
- Handle missing values by replacing with None
- Single docstring line
- No external libraries

Reinforcement Trick

Repeat format instructions at the end:

[Main instruction here]

Remember: respond ONLY with valid JSON. No prose, no explanation.

Part of a structured course

Prompt Engineering Fundamentals

Master prompt engineering from zero — learn to write effective prompts, control LLM behavior, and build reliable AI applications. Free 6-week beginner course.

Lesson 6 of 10 ⏱ 6 weeks beginner Free

Related Tutorials

🔰beginner ⏱️ 90 minutes

Prompt Chaining: Build Multi-Step AI Pipelines

Learn how to connect multiple prompts into pipelines where the output of one step becomes the input of the next — enabling complex, reliable AI workflows.

AI Engineering2 min read
prompt engineeringprompt chainingpipeline +2