How to Write true and false in YAML
A YAML setting that's on or off is written true or false. In PyYAML, which follows YAML 1.1, a whole list of other words count too: yes, no, on, off. So a country code NO, for Norway, quietly becomes False. This guide writes booleans and checks them with Python.
Syntax
<key>: true
<key>: false
trueandfalse: the two boolean values. They load as Python'sTrueandFalse.
The YAML 1.1 boolean type, which PyYAML follows, accepts far more words than these two. Its regular expression is y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF.
The Example
booleans.yaml says whether a shop delivers and whether it gift-wraps.
Prerequisites
- uv and Python, with PyYAML in a project (
uv add pyyaml), to check the file. This guide uses PyYAML 6.0.4 on Python 3.15.2.
Step 1: Write the File
delivery: true
gift_wrap: false

Step 2: Check It with PyYAML
Save this checker as show.py. It loads any YAML file you give it and prints the result:
import sys
from pprint import pp
import yaml
with open(sys.argv[1], encoding="utf-8") as file:
pp(yaml.safe_load(file))
uv run python show.py booleans.yaml
{'delivery': True, 'gift_wrap': False}

true and false became Python's True and False. The command works unchanged in PowerShell.
The Other Words
This file uses three of the YAML 1.1 words, and one of them is a country code:
delivery: yes
gift_wrap: off
country: NO
{'delivery': True, 'gift_wrap': False, 'country': False}
yes and off became booleans, and so did NO, meant as Norway. In quotes, country: "NO" loaded as the text 'NO'. YAML 1.2 dropped these words: its core schema reads only true | True | TRUE | false | False | FALSE as booleans.
Common Mistakes
| Mistake | What PyYAML did | Do this instead |
|---|---|---|
A two-letter code without quotes: country: NO | Returned False | Quote it: country: "NO" |
Answers written as words: delivery: yes | Returned True, which may not be what a reader of the file expects | Write true and false, so every YAML version agrees |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
A text setting arrives as True or False | Its value is one of the YAML 1.1 boolean words | Quote it |
FAQ
Does case matter?
Not for the forms in the list. True and FALSE loaded as True and False, just like true and false.
Why do other YAML tools treat yes differently?
Because they follow YAML 1.2, which reads yes as text. Writing true and false gives the same result in both.
Conclusion
delivery: true and gift_wrap: false loaded as True and False. In PyYAML, yes, off and NO did too, so write booleans as true and false, and quote codes that look like one of those words.
Additional Resources
- YAML 1.1 boolean type — every word PyYAML reads as a boolean.
- YAML 1.2.2 core schema — the newer, shorter list.
