Markdown and YAML: a primer for working with agents
How to read, edit and check Markdown files with a YAML block, the format most agent work is kept in.
Most of what I keep, and most of what my agents write for me, is a Markdown file with a short block of YAML at the top. Notes, chapters, interview records, converted documents, survey responses and the instructions my agents work from are all in this form. The other guides in this series mention it in passing. This one explains it in enough detail that you can read such a file, make small edits to it with confidence, and check that an agent is writing the files the way you want.
Each step has its own guide in this series - co-written with my agents based on the work they did for me. To make it simple, I use first person throughout:
- Publishing research results with Cloudflare: putting a folder of files online at a public address.
- Building research sites from data files: Astro and fast search: turning data files into a site people can search.
- Git and GitHub for sharing data with agents (coming soon): keeping the files where collaborators and their agents can work on them.
- Spreadsheets and tabular data with agents: turning workbooks into tables an agent can maintain.
- From a pile of mixed documents to an agent-friendly knowledge repository: turning documents into a repository an agent can maintain.
- Data formats for working with agents: an overview: which format to keep research data in.
- Markdown and YAML: a primer for working with agents (this guide): reading, editing and checking the format most of those files use.
- XML and TEI: when a text needs annotation inside it: marking up a text itself, for editions and similar work.
What a Markdown file is
A Markdown file is plain text. It contains only characters, with no hidden formatting, no embedded fonts and no package of files inside it. The marks that give a text its structure are ordinary characters: a heading starts with #, a list item with -. A person or an agent can both read it in any editor. The usual ending for the file name is .md, which tells programs what is inside but it could just as easily be .txt.
Plain text lasts. The first file in Project Gutenberg, from 1971, is still readable. A Word file needs software that understands its format, and software changes. That is why I keep the record as Markdown files and have the agent convert Word and PDF originals into this form (see the overview of formats, or the explainer, which puts a Word file and a Markdown file side by side).
Unfortunately, many computers will not open a .md file automatically, so it is a good idea to install a Markdown editor. I made my own, called WriteFlex. Many people use Obsidian on their desktop, and Notion also stores all its contents as Markdown. People who work with code will have a text editor such as VS Code, which also makes it easy to work with Markdown. If you don't have a Markdown editor, you can still open Markdown files in Notepad.
The Markdown you need
You need about ten codes to type Markdown comfortably. Each is shown as you type it, with what it is for.
Headings
# Water point check
## Method
### Sampling
One to six # characters, then a space, then the text. The number of # characters is the level. A heading without the space is not a heading: #hashtag stays ordinary text. The levels matter to an agent because they form the outline of the file, which it can use to find the section you mean. A document needs one top-level heading and each level below it nested in order: a ### straight after a # leaves a gap in the outline.
Paragraphs and line breaks
First paragraph, written on
two lines in the file.
Second paragraph.
A paragraph is a run of lines with no blank line in between, so the two lines of the first paragraph belong together. A blank line starts a new paragraph. If you need a line break inside a paragraph, end the line with two or more spaces, or with a backslash.
Lists
- A bullet item
- Another bullet item
1. First numbered item
2. Second numbered item
A bulleted list uses -, + or * and a numbered list uses a number followed by . or ). Each marker is followed by a space. Use one kind of marker throughout a list, because changing it starts a new list.
Emphasis
*italics* or _italics_
**bold** or __bold__
One asterisk or underscore gives italics and two give bold. Note that __text__ is bold, not italics.
Links and images
[the explainer](https://semanticmachines.fyi/explainers/data-structures-and-formats/)

A link is the text in square brackets followed by the address in round brackets. An image is the same with a ! in front, and the text in the square brackets is the description that screen readers read out.
Quotations
> Plain text lasts.
A line that starts with > is a quotation. Put it on every line of a longer quotation.
Code and fenced blocks
Run the check with `check.py`.
```
date,station,temperature_c
2099-04-01,Plim-1,9.4
```
A word or phrase between single backticks is shown as code. For several lines, put a line of three backticks above and below. Everything between the fences is shown exactly as typed, so I use them for examples of files and commands, as in this guide.
Tables
| station | temperature_c |
|---|---:|
| Plim-1 | 9.4 |
| Wug-2 | 7.2 |
Markdown supports tables too, but just like CSVs they are not easy to write or read by hand. A cell cannot hold a paragraph or a list and cannot run over several lines. When the table is small and regular, keep it as a CSV file. When the cells would hold long text, give each item its own file (see below). A short table inside a document is fine.
Extensions some tools support
Footnotes ([^1] in the text and [^1]: The note. below it) and task lists (- [ ] to do, - [x] done) are documented in Pandoc's version of Markdown. Pandoc is a program that converts documents between formats. Whether they display depends on the tool.
Dialects
Markdown has several dialects. CommonMark is a written specification of the common core: headings, paragraphs, lists, emphasis, links, images, quotations and code, as above. Tools add extensions on top. Tables and task lists are extensions, and so is the YAML block described next. Ask your agent to keep to the common core unless the tool that will display the file needs more.
The YAML block
YAML is a notation for named fields. In a Markdown file it sits at the top, between two lines of three dashes:
---
title: Water point check, northern district
date: 2099-03-14
status: checked
---
## Method
The text of the record starts here.
The first line of three dashes must be the first line of the file, and it must not be followed by a blank line. Each field is a name, a colon, a space and a value. The block is for fields and the text below it is Markdown as before.
Kinds of value
title: Water point check, northern district # text
visits: 12 # a number
score: 3.5 # a number with decimals
date: 2099-03-14 # a date, year first
reviewed: true # true or false
notes: # no value: empty
Text needs no quotation marks in the simple case. true and false stand for yes and no. A field with nothing after the colon is empty.
A list has one dash and a space for each item, or the items go in square brackets on one line:
keywords:
- water
- survey
districts: [north, east]
A nested group is a field whose value is a set of fields, indented below it:
source:
file: sources/water-point-check.pdf
converted: 2099-03-20
The mistakes that break it
A YAML block that does not parse is useless to a tool, and the fault is usually one of these.
- A colon followed by a space inside unquoted text. YAML reads the colon and space as the end of a field name.
title: Survey: northern districtis a mistake, and the title needs quotation marks. - No space after the colon.
title:Water pointis not a field. - Tabs for indentation. YAML structure comes from indentation, and the specification says tab characters must not be used for it. Use spaces.
- Indentation that does not match. A line indented differently from its neighbours changes what belongs to what.
- A
#after a space. It starts a comment, and the rest of the line is ignored. - A blank line after the first
---.
Large language models that power agents write properly formatted YAML reliably which is why it is best to let them be the main writers of metadata.
When to quote a value
Put a value in quotation marks when it contains a colon followed by a space or a #, when it begins with a character YAML uses for something else (such as [, * or #), or when it must stay text although it looks like something else. respondent_id: "001" is an example from my survey files. Without the quotation marks YAML reads 001 as the number 1. The same goes for a value such as true that you mean as a word.
title: "Survey: northern district"
respondent_id: "001"
note: 'It''s a draft'
Double quotation marks allow escapes with a backslash, so a backslash or a double quotation mark inside has to be escaped. In single quotation marks only the single quotation mark itself is doubled, as in 'It''s'.
Which fields to put there
The fields I use most are these.
titleanddate. What the file is and when it was last written or converted.status. Where the file stands: converted, checked, draft.register. Who the text is written for. In my files there are three values: for agents, for me, and as me.sources. The provenance: where the file came from, when, and how it was converted.
A file converted from a PDF carries all of these:
---
title: Water point survey report
date: 2099-03-20
status: converted, checked against the original
sources:
- file: sources/water-point-survey-report.pdf
origin: district office web page, downloaded 2099-03-10
converted: 2099-03-20, tables checked by hand
---
With the provenance in every file, anyone who receives the files, a colleague or their agent, can trace a statement back to the original document. I keep three things apart: the sources (the originals, unchanged), the content (the Markdown) and the rendering (the website or ebook generated from it). The knowledge repository guide describes this.
Two rules decide what goes in the YAML block. Short values you want to sort and filter on go in YAML: a date, a status, a role, a rating. Long text goes in the body under headings. The second rule is to use the same field names in every file of a collection. A field called status in one file and state in another cannot be filtered together.
One record per file
A folder of such files works as a small database. Each file is one record: one interview, one survey response, one converted document. Here is the start of one respondent from the fictional survey in the tabular data guide, as it is in respondent-001.md:
---
respondent_id: "001"
role: "Doctoral researcher"
discipline: "History"
q1: {"question": "I feel confident deciding when to use AI tools in my research.", "answer": 3, "label": "Neither agree nor disagree"}
---
## Biggest benefit
I work with boxes of invented parish accounts for a teaching project, and the getting started part is what takes me longest.
The short fields are in the YAML and the long answers are under headings. The question and its answer are written on one line, as a group in curly brackets. YAML accepts JSON written this way. The file also shows the quoting rules at work, as respondent_id is in quotation marks to keep the leading zeros.
A file name should make sense in a search result or a list of recent files, without its folder. These are the rules I use.
- Lowercase, with hyphens between words.
- Role first, then subject, then date or version. For example
review-water-points-2099-03.md. - No bare generic names such as
notes.mdordraft.md. - Names that tools look for stay as they are:
README.md,AGENTS.md,SKILL.md. - One stable name. The name identifies the file and does not change when the content does. Put the changing state in
status.
Because the fields are named and consistent, an agent can sort the folder by date, filter it by status and build a table or a site from it. Section 3 of the explainer lets you try the fields on a list of six records.
What an agent does with these files
- Filters by field. It sorts by date, filters by status or looks up a title without reading the paragraphs below the block.
- Converts. It converts a copy of a Word file or PDF into this form with a script, and the original stays unchanged.
- Builds views. It builds tables, viewers and sites from the files. The survey viewer in the tabular guide is generated from the respondent files by a short script, which the agent reruns whenever a file changes.
- Checks. It runs a validation script that checks every file has frontmatter with the agreed fields. For a knowledge repository, I have it check that every content file names its sources and that every named source exists.
When this format is not enough
Markdown with YAML fits records and prose. For larger regular tables of numbers, dates and short text, CSV is simpler; the tabular data guide covers it. When each value in an item needs its own label, as in a dictionary entry with an example sentence and a translation, JSON keeps the labels with the values; the overview of formats explains why. When the text itself needs annotation inside it, such as variant readings in an edition, the format for that is XML and TEI, covered in XML and TEI: when a text needs annotation inside it.
Give this guide to your agent
Copy this and give it to your agent (Claude Code, Codex or another). The agent can read the whole guide and the rest of the series on this site, each page also as a Markdown file written for agents.
Read https://semanticmachines.fyi/guides/markdown-and-yaml-primer (and https://semanticmachines.fyi/llms.txt for the rest of the series), then help me write and maintain my Markdown files with YAML the way it describes. Start by asking me what files I have and what I want to do with them.
What your agent takes from this guide
This is the practice the guide describes, written for the agent. It is here so that you can see what your agent will work from.
# Practice: Markdown files with a YAML block
Purpose: write Markdown files with a YAML block that the user can read and
edit and that agents can sort, filter, check and build from.
## Markdown
- Use CommonMark constructs. Use extensions (tables, footnotes, task lists)
only if the tool that will display the file needs them; ask the user.
- One top-level heading (`#`) per file. Never skip a level: `##` follows `#`.
- Italics is `*text*` or `_text_`; bold is `**text**`. `__text__` is bold.
- Use a CSV file for a regular table. No long text in Markdown tables.
- Do not reformat, reflow or reword the user's prose. Change only what was
asked.
## YAML block
- `---` on line 1, no blank line after it, `---` to close.
- Write `name: value` with a space after the colon. Indent with spaces, never
tabs, and consistently.
- Quote a value that contains `: ` or ` #`, starts with `[`, `*`, `#` or
another YAML punctuation mark, or must stay text but looks like a number,
`true` or `false` (for example `"001"`).
- Short values (dates, statuses, codes) in YAML. Long text in the body under
headings.
## Fields and files
- Agree the fields with the user before writing files. Start with `title`,
`date`, `status` and `sources` (origin, date, how converted).
- Use the same field names and date format (year-month-day) in every file of
a collection.
- One record per file. Name it for its content: lowercase words joined by
hyphens, role then subject then date. No `notes.md` or `draft.md`. Keep
`README.md`, `AGENTS.md` and `SKILL.md` as they are.
- One stable name per file. Do not rename a file when its content changes.
- Ask the user before renaming, moving or restructuring files.
## After any change
- Run a script that parses the YAML block of every file and checks the agreed
fields are present. Fix failures before finishing.
- Record the agreed fields and naming rules in AGENTS.md.