jypi
  • Explore
ChatWays to LearnMind mapAbout

jypi

  • About Us
  • Our Mission
  • Team
  • Careers

Resources

  • Ways to Learn
  • Mind map
  • Blog
  • Help Center
  • Community Guidelines
  • Contributor Guide

Legal

  • Terms of Service
  • Privacy Policy
  • Cookie Policy
  • Content Policy

Connect

  • Twitter
  • Discord
  • Instagram
  • Contact Us
jypi

© 2026 jypi. All rights reserved.

Generative AI: Prompt Engineering Basics
Chapters

1Foundations of Generative AI

2LLM Behavior and Capabilities

3Core Principles of Prompt Engineering

4Writing Clear, Actionable Instructions

5Roles, Personas, and System Prompts

6Supplying Context and Grounding

7Examples: Zero-, One-, and Few-Shot

8Structuring Outputs and Formats

Bullets, Lists, and OutlinesHeadings and SectionsJSON and Schema EnforcementXML, CSV, and TSV OutputsMarkdown and Code BlocksTags, Markers, and DelimitersLength Targets and SummariesScoring Rubrics and ScalesKey-Value Output PatternsPlaceholders and VariablesError Message ConventionsStructured Reasoning FieldsTables and MatricesMulti-Part Output AssemblyPost-Processing Friendly Designs

9Reasoning and Decomposition Techniques

10Iteration, Testing, and Prompt Debugging

11Evaluation, Metrics, and Quality Control

12Safety, Ethics, and Risk Mitigation

13Tools, Functions, and Agentic Workflows

14Retrieval-Augmented Generation (RAG)

15Multimodal and Advanced Prompt Patterns

Courses/Generative AI: Prompt Engineering Basics/Structuring Outputs and Formats

Structuring Outputs and Formats

20817 views

Specify output schemas, enforce structure, and design responses for easy parsing, scoring, and downstream use.

Content

5 of 15

Markdown and Code Blocks

Markdown & Code Blocks: The Chaotic-Precise Guide
1236 views
beginner
humorous
education theory
science
gpt-5-mini
1236 views

Versions:

Markdown & Code Blocks: The Chaotic-Precise Guide

Watch & Learn

AI-discovered learning video

Sign in to watch the learning video for this topic.

Sign inSign up free

Start learning for free

Sign up to save progress, unlock study materials, and track your learning.

  • Bookmark content and pick up later
  • AI-generated study materials
  • Flashcards, timelines, and more
  • Progress tracking and certificates

Free to join · No credit card required

Markdown and Code Blocks — the pretty, parseable output style

You're coming in hot from JSON/schema enforcement and CSV/XML outputs. Those taught you how to make machines happy with rigid formats; now let's make humans (and machines) both happy using Markdown and fenced code blocks. This is the bridge between readable documentation and reliably parseable payloads — the sweet spot where clarity meets automation.

"Markdown is what humans read. Code blocks are what machines parse (and devs admire)." — Your future self, after shipping clean docs


Why Markdown + Code Blocks?

  • Human-first: Markdown is readable without rendering. Headings, lists, and emphasis help quick comprehension.
  • Machine-friendly: Fenced code blocks with a language tag (json, python) give parsers clear, extractable blobs.
  • Versatile: Use it for README-style answers, example payloads, command snippets, or embedding structured outputs.

Think of Markdown as a layered cake: the frosting (headings, prose) makes it appetizing; the cake layers (code blocks) deliver the payload.


When to use Markdown vs. raw JSON/CSV

Use case Prefer Markdown Prefer JSON/CSV
Human-facing instructions ✅ ❌
Machine-to-machine strict data ❌ ✅
Mixed: docs + example payload ✅ (with code block) ⚠️ (wrap JSON in code block)

If the consumer is a program, give them raw JSON/CSV. If it's a person or a person-plus-toolchain, wrap structured data inside code blocks in Markdown.


Practical patterns and prompt snippets

1) Enforce 'Markdown-only' output

Prompt trick: be explicit and terse.

Respond only in valid Markdown. No explanations, no additional text.
Produce a level-2 heading 'Summary' and a fenced code block labelled 'json' containing a single JSON object with keys: name, tags.

Why this works: you remove ambiguity. The model can't sneak in extra prose if you forbid it, and you specify structure.

2) Embed JSON inside Markdown (for both humans and machines)

Example desired output (what you'd expect the model to return):

## Payload Example

```json
{ "name": "Alice", "age": 30, "skills": ["python", "prompting"] }

Use the language tag (json) so syntax highlighters and many parsers will recognize it.


Note: In the example above the inner JSON is the structured data you can extract programmatically.

### 3) Provide a golden example (few-shot) and a bad example

Few-shot wins when you need style and form. Show one high-quality exemplar and one forbidden format.

Good exemplar (put this first or last depending on the model/version; test order effects):

```text
---GOOD EXAMPLE---
## Result

```json
{ "id": 42, "status": "ok" }

---END---


Bad exemplar:

```text
---BAD EXAMPLE---
Result: id=42 status ok
(plain text, no code fences)
---END---

Why contrast helps: the model learns not just what to do, but what not to do. Remember order effects — in some models the last example has more pull; in others the first does. If behavior is inconsistent, experiment: put the golden example last.


Common pitfalls and how to avoid them

  • Extra text outside the code block
    • Mitigation: explicitly say 'only the fenced code block' and show an example that contains only the code block.
  • Incorrect language tag (js vs javascript)
    • Use the conventional tag for parsing tools (json, python, ```bash).
  • Unescaped triple backticks inside content
    • If you must include ``` inside a fenced block, fence the outer block with 4 backticks (````) or use indentation or HTML entities.
  • Model adds commentary like 'Here is the result:'
    • Force brevity: 'Return only the Markdown content; no preface or explanation.'

Validation: quick strategies

  • For JSON inside a code block: extract the block with a regex and run a JSON parser.
  • For required sections (heading + code block): validate with a lightweight rule-set (pseudo):
if not markdown.contains('## Summary') -> reject
json_blob = extract_fenced_block(language='json')
if parse_json(json_blob) fails -> reject

Automate this in your pipeline so the model's output is validated before being used downstream.


Advanced tips (tricks only the pros whisper about)

  • Use YAML front matter for metadata. Start your Markdown with:
---
format: example
version: 1
---
  • For ultra-strict output, require the model to produce a single fenced block with a specific language tag. Example instruction: 'Output exactly one fenced block delimited by json and with only a compact JSON object.'
  • If you need the model to include literal code fences inside the response, use 4 backticks to fence the outer block and 3 for the inner, or instruct the model to use HTML code entities.

Quick reference: Dos and Don'ts

  • Do: Specify language tags in code fences (json, bash).
  • Do: Provide a golden example if you need precise formatting.
  • Don't: Ask for prose and code and expect consistent structure — separate responsibilities.
  • Don't: Trust visual inspection for structured data — parse and validate.

Closing — takeaways (so you can act fast)

  • Markdown + code blocks = human-readable docs + machine-readable payloads. Use both when you need the best of both worlds.
  • Few-shot examples steer style — show a perfect example and (optionally) a bad one. Watch order effects and test.
  • Validate outputs — extract fenced blocks and run parsers. Never assume correctness.

Action checklist:

  1. When you want human + structured data, ask for Markdown with a fenced code block.
  2. Provide a gold example (one high-quality exemplar). If the model misbehaves, swap example order and retry.
  3. Implement automated checks for the presence of the required heading and code-block-parsable content.

Go forth and make your chatbot outputs pretty, precise, and unambiguously useful. If Markdown is a polished storefront, fenced code blocks are the neatly labeled products on the shelf — people can browse, bots can buy.

Flashcards
Mind Map
Speed Challenge

Comments (0)

Please sign in to leave a comment.

No comments yet. Be the first to comment!

Ready to practice?

Sign up now to study with flashcards, practice questions, and more — and track your progress on this topic.

Study with flashcards, timelines, and more
Earn certificates for completed courses
Bookmark content for later reference
Track your progress across all topics