How to Prompt AI to Fill a Template Correctly

Hand a model a contract template and ask it to fill the blanks, and it will helpfully improve your wording, merge two sections and quietly delete a clause. Here is how to stop that.

Steve Jefferson
Steve Jefferson
Developer Advocate
25 August 20261 min read

How to Prompt AI to Fill a Template Correctly

The way to prompt AI to fill a template without it breaking is to tell the model that the template is data, not a draft. Give it the template verbatim, mark the fields with a syntax that cannot appear in normal prose, forbid changes to anything outside those markers, and run a mechanical diff afterwards. Without those four things a model treats your template as a document it has been asked to improve, and it will improve it.

This matters for proposals, contracts, offer letters, statements of work, incident reports, and anything else where the wording was agreed by someone who is not you.

Why models rewrite templates

A template looks like a first draft. It has slightly stilted language, repeated structures, and obvious gaps. Every instinct a language model has says to smooth that out. So it does: it fixes what it reads as awkward phrasing, merges two short sections that seem redundant, and drops a clause that appears to say the same thing as an earlier one.

That behaviour is desirable in almost every other task, which is why the fix has to be explicit rather than implied. Politeness does not work. "Please keep the template mostly the same" gives the model discretion, and it will use it.

Rule 1: Separate the template from the instruction

Put the template inside a delimiter that clearly marks it as content, and put your instructions outside it. Models handle this reliably and it prevents the template's own wording from being read as instructions to follow.

You are filling a fixed template. The template is between the
markers below and is not to be edited except where specified.

<<<TEMPLATE
STATEMENT OF WORK

This agreement is made between {{CLIENT_LEGAL_NAME}} and
{{SUPPLIER_LEGAL_NAME}} on {{AGREEMENT_DATE}}.

1. Scope
{{SCOPE_DESCRIPTION}}

2. Payment terms
Invoices are payable within {{PAYMENT_DAYS}} days of receipt.
TEMPLATE>>>

The curly-brace placeholder style matters more than it looks. Use a marker that will never occur in the surrounding prose, so both you and the model can find every field with a plain text search. Square brackets are a poor choice because legal documents already use them.

Rule 2: State the edit rule as a prohibition

One sentence, phrased as what is forbidden rather than what is allowed.

Replace every {{FIELD}} marker with its value from the data below.
Change nothing else. Do not reword, reorder, merge, split, shorten
or add sections. Preserve line breaks, capitalisation and
punctuation exactly as they appear.

Prohibitions work better than permissions here because the space of allowed edits is exactly one thing and the space of unwanted edits is enormous. It is worth reading why telling AI not to do something does not always work alongside this, because the general advice is the opposite. Templates are the exception: the prohibition is precise and mechanically checkable, which is what makes it hold.

Rule 3: Supply data as data, and name the missing pieces

Give values in a structured block, not in a sentence. And decide in advance what happens when a value is absent, because that is where invention happens.

DATA:
CLIENT_LEGAL_NAME: Northgate Interiors Ltd
SUPPLIER_LEGAL_NAME: Marlowe Studio GmbH
AGREEMENT_DATE: 2026-09-01
PAYMENT_DAYS: 30
SCOPE_DESCRIPTION: [MISSING]

If a value is [MISSING] or absent, leave the marker in place
unchanged. Never guess, never write a placeholder of your own,
never write "TBD".

Leaving the original marker in place is deliberate. A document that still contains {{SCOPE_DESCRIPTION}} is obviously incomplete to any human who opens it. A document containing "To be determined" looks finished and ships.

Rule 4: Verify with a diff, not a read

This is the step that turns the previous three from hopeful into reliable. Do not proofread the output. Diff it.

  1. Take the original template and the filled output.

  2. Replace every {{FIELD}} in the original with the value you supplied, using a plain find-and-replace in your editor or a two-line script.

  3. Diff that against the model's output.

  4. Any difference at all is a defect. There should be zero.

This catches the failure mode that reading misses entirely, which is a single deleted sentence in the middle of section 4. Human proofreaders are bad at spotting absence. Diffs are perfect at it.

If you are doing this at volume, the diff belongs in code, and at that point you may reasonably ask why you are using a model to do find-and-replace. Fair question, and the honest answer is that for pure substitution you should not. The model earns its place when some fields require judgement, such as turning three bullet points of notes into a scope paragraph in the register the template uses.

A worked check for the judgement fields

For fields where the model is generating rather than substituting, add a constraint per field rather than one general instruction.

Field type

Constraint to state

Free-text description

Maximum sentence count, and "use only facts present in the notes below"

Money or dates

Format string, and "copy exactly, do not recalculate"

Names and entities

"Copy character for character, including legal suffixes"

Lists

Exact number of items, or "one item per input line, no merging"

The money row matters more than it looks. Models will happily convert 30 days to "one month", reformat 2026-09-01 as "1 September 2026", or round a figure. In a contract those are not cosmetic changes.

When the template itself is the problem

If the model keeps mangling one section, read that section again. Templates that confuse models usually confuse people too: nested conditionals in prose, a placeholder inside a sentence that only makes grammatical sense for some values, or two fields that must agree but are 40 lines apart. Fixing the template is often faster than fixing the prompt.

Once a template and prompt pair works, save it as a unit. Both halves are load-bearing and a prompt that works for one template will not transfer cleanly to another. Our guide on building a reusable prompt library covers storing those pairs so the team stops rebuilding them, and how to version your prompts covers what to do when the template changes underneath.

For the wider problem of getting the same output shape every time, see getting consistent AI output every time. If your template is really a data structure rather than a document, getting JSON output from AI is the better tool. And the foundations of all of this sit in our prompt engineering guide.

FAQ

What placeholder syntax works best for AI template filling?

Double curly braces with uppercase field names, such as {{CLIENT_NAME}}, work well because they are visually distinct, unlikely to appear in prose, and easy to search for. Avoid square brackets and single braces, which already appear in legal and technical documents.

How do I stop AI reformatting dates and numbers in a template?

State the format explicitly per field and add "copy exactly, do not reformat or recalculate". Then verify with a diff rather than by reading, since a reformatted date is easy to skim past and easy for a diff to catch.

Why does AI delete sections of my template?

Usually because two sections look redundant to a reader who does not know why both exist. Adding a line stating that every numbered section must appear in the output, with its original number, fixes it in most cases. Counting sections in the output is a cheap automated check.

Can I fill a template with a cheap AI model?

Yes, for pure substitution a small model is fine and often more literal, which is what you want. Judgement fields that require summarising notes into prose benefit from a stronger model, which is an argument for splitting the job into two calls rather than paying frontier prices for find-and-replace.

For mechanical fields, with a diff check and a human approving the result, this is a reasonable time saver. For anything where the wording carries legal weight and the model is generating rather than substituting, the output needs a qualified human review before it goes anywhere. The diff step tells you exactly which parts need that scrutiny.

How did this land?

About the author

Steve Jefferson
Steve Jefferson

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.

Share

Get the next post in your inbox

One email a month. Product updates, engineering posts, and the best of Built with Swarmz.

I agree to receive emails about AI building tips and Swarmz product news. Unsubscribe any time.