How to Get AI to Return a Clean Markdown Table
How to get AI to return a markdown table that survives the paste: fix ragged columns, swallowed pipes, and tables that arrive as prose instead.
To get AI to return a markdown table, name the columns in the prompt, state what belongs in each one, and say explicitly that the response must be the table and nothing else. Most broken tables are not a formatting failure. They are a specification failure: you asked for "a table" and left the model to invent the schema, the column count, and whether commentary was welcome.
Here is the version that works, and then the four ways it still goes wrong.
How to get AI to return a markdown table in one pass
The prompt below is the whole technique. Everything after it is a diagnosis of what goes wrong when one of its four clauses is missing.
Return a markdown table with exactly these columns, in this order:
| Tool | Monthly cost | Free tier | Best for |
Rules:
- One row per tool. 8 rows.
- Cost as a number with currency, or "Varies" if usage-based.
- Free tier: Yes or No only.
- Best for: at most 6 words.
- If you do not know a value, write "Unknown". Never guess.
- Output the table only. No heading, no intro, no notes after it.Four things are doing work there. The column list removes schema invention. The per-column rules remove ragged content. The Unknown instruction removes quiet fabrication. The output-only line removes the paragraph of throat-clearing that breaks the paste.
Failure one: the table arrives as prose
You asked for a table and got four paragraphs that each describe a tool. This happens when the request is buried in the middle of a longer prompt, or when the model judges the content too nuanced for cells.
Fix it by putting the format instruction last and making it the final thing the model reads. Recency matters more than emphasis. If it still narrates, give it the header row verbatim, as above, and it will fill rather than describe. The general pattern is in prompt AI with a worked example: showing the shape beats describing it.
Failure two: the columns go ragged
The table renders, but one cell holds a 40-word explanation and the rest hold three words, so the whole thing is unreadable at any width.
Per-column length limits fix this, and they have to be numeric. "Keep it brief" produces nothing; "at most 6 words" produces six words. For any column that is genuinely a judgement, allow a fixed vocabulary instead of free text:
- Risk: one of Low, Medium, High. Nothing else.
- Why: at most 10 words, no semicolons.Constraining a column to a fixed set also makes the output sortable later, which free text never is.
Failure three: pipes inside the data break the columns
This is the one that catches people, because the table looks fine until a single row quietly gains a column. Any pipe character inside cell content is read as a column separator, as the GitHub Flavored Markdown spec sets out. The same applies to a stray line break inside a cell.
If your data could contain pipes, say so:
If a value contains the | character, escape it as \| .
Never put a line break inside a cell. Use a comma instead.Empty cells cause a related problem. A fully empty cell is legal markdown but some renderers collapse it, so the row shifts left and every value after it lands in the wrong column. Requiring a literal placeholder, as the first prompt does with Unknown, prevents it entirely. This is the same class of bug as the shape failures in how to get JSON output from AI reliably: valid syntax, wrong structure.
Failure four: it looks right and the numbers are invented
A well-formatted table is persuasive in a way a paragraph is not, which makes this the expensive failure. Columns have a gravitational pull toward being filled, and a model asked for eight rows will produce eight rows whether or not it knows eight answers.
Two defences. First, the Unknown rule, enforced rather than suggested. Second, a source column:
Add a final column: Source. Put the URL you took the value from, or "Not verified" if you are working from memory.Expect a lot of Not verified, and treat that as the prompt working. A table where two rows cite a URL and six admit they do not is far more useful than eight confident rows. The related habit is in how to prompt AI for a complete list, not a sample.
Making the table survive the paste
Markdown tables paste cleanly into anything that speaks markdown and badly into everything else. If the destination is a spreadsheet or a document editor, ask for the format that destination actually wants:
Destination | Ask for |
|---|---|
Notion, GitHub, Slack canvas | Markdown table |
Google Sheets, Excel | CSV in a code block |
Google Docs, Word | Tab-separated values, then Paste special |
Your own app | JSON array of objects, one object per row |
The CSV and tab-separated requests need one extra clause: wrap the output in a code block so your chat client does not helpfully reformat it. For anything that feeds code rather than a human, skip tables and go straight to JSON.
Keep the prompt once it works
A table prompt that has survived four rounds of fixes is a small asset. Save it with the column list intact, since that is the part doing the work, and reuse it rather than re-deriving it. How to build a reusable prompt library covers how to store these so they are findable later, and how to version your prompts covers what to do when the schema changes. The habit of specifying structure rather than hoping for it is the whole of the wider prompt engineering framework.
FAQ
Why does AI keep adding text before and after my table?
Because nothing told it not to. Add an explicit final instruction: output the table only, with no heading, introduction, or closing note.
How do I stop AI making up values in a table?
Require a literal Unknown for missing values and add a Source column asking for the URL or "Not verified". Empty cells invite invention; a required placeholder does not.
Why does one row of my markdown table have extra columns?
Almost always an unescaped pipe character inside a cell value. Instruct the model to escape pipes and to never put line breaks inside cells.
What is the best format for pasting an AI table into Google Sheets?
Ask for CSV inside a code block, not a markdown table. Markdown pipes do not map to spreadsheet columns on paste.
How did this land?
About the author

Developer Advocate
Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.


