Paste YAML Without Losing Indentation

AI-assisted article. Reviewed by Codebuff automated editorial review on 2026-11-08. Examples are illustrative, not real user data.
A YAML error is usually an indentation error, which makes it the one file type where a paste that looks correct can be useless. Leading spaces get trimmed by chat windows, re-indented by editors with different tab settings, and rewritten by formatters. If the report does not preserve the exact indentation, the reader is debugging a different document.
Why send the file instead of a summary?
Describe the failing line separately and paste the file as it is. Retelling the structure in prose removes the evidence, because the prose is where the indentation was already corrected by the person writing it.
If the file is long, paste the smallest block that still fails. A fragment that reproduces the error is more useful than the full manifest, and it is less likely to contain unrelated addresses and names.
services:
api:
image: example/api:1.4.2
environment:
- LOG_LEVEL=info
ports:
- 8080:8080
Show the invisible characters
A tab where a space belongs is valid in some positions and invalid in others, and it looks identical to a reader. Turn on visible whitespace in the editor before copying, and say in the message whether the file uses spaces or tabs.
Trailing spaces are the other invisible character. They matter inside a block scalar, where they are preserved, and they are stripped by many paste and chat interfaces, which quietly changes a value that spans several lines.
Keep the error message with the file
The parser's line number is the link between the message and the structure, and it counts lines that a summarised paste may not have. Paste the message unedited, including the parser's name and the exact column if it reports one.
Do not retype the message into your own words. A parser that says it expected a block mapping at line 14, column 3 has told the reader something a paraphrase cannot.
# Keep the parser's own words and its line and column
# yaml: line 14: could not find expected ':'
# in "config.yml", line 14, column 3
Remove values before you remove structure
It is tempting to delete whole blocks to make the file safe to share. That changes the structure and often removes the line that fails. Replace the values instead: keep every key, every nesting level and every list item, and put a placeholder where a secret was.
For a file that must keep real values, use a password or browser-side encryption and send the password by another route. That protects the contents in transit and at rest, but it does not protect a recipient who pastes the file onward.
Check the paste after it is saved
Open the paste, copy it back and compare the indentation against the original file. This catches an interface that converted tabs, collapsed blank lines or wrapped a long scalar, and it takes less time than the round trip caused by a report nobody can reproduce.
If the paste renders inside a formatted page, use the raw view for the comparison. The rendered view is the one that is easiest to trust and least likely to be what the reader actually copies.
Sources and editorial review
Prepared with AI assistance and checked against the YAML and log sharing pages at the reviewed revision: indentation as syntax, tabs versus spaces, trailing spaces in block scalars and the raw-view comparison. No YAML parser was run and the error text is illustrative.