voidduck
AI guides

How to write an AI prompt: context, examples and a testable format

Write clearer AI prompts with a task, source material, output format and checks. Use examples for edge cases, then validate the result.

Published: Updated: 5 min read

Typewriter with the words Artificial Intelligence

© Markus Winkler / Pexels.

Updated: November 26, 2026.

A useful prompt tells the model what to produce, what information to use and how you will judge the result. “Write something about privacy” leaves the model to guess the audience, scope and format. A short brief can remove those guesses without turning every request into a long template.

Define the result before writing the prompt

First decide what a correct answer looks like. Is it a customer email, a JSON object, a code diff or a comparison? Then include the constraints that would change the result.

For a customer email, the useful details might be:

  • the customer knows the issue but not your return process,
  • use only the policy text supplied below,
  • write in a calm tone and stay under 120 words,
  • do not promise a date that the policy does not contain,
  • mark missing information as [confirm].

That is more useful than telling the model to “act as an expert.” A role can set vocabulary or perspective, but it cannot supply missing facts or make the answer authoritative.

A prompt template you can trim

Use the fields that remove ambiguity. Skip the rest.

Task: [what to produce]
Audience: [who will use or read it]
Source material: [text, data or limits]
Format: [table, JSON, list, code]
Checks: [length, required fields, what to avoid]
If information is missing: [ask / mark the gap / do not guess]

For example:

Rewrite the customer message below.
The reader knows the issue but not our returns process.
Keep every fact from the supplied text. Do not add dates or promises.
Write in English, under 120 words, in three short paragraphs.
Mark any missing information as [confirm].

This prompt is testable. You can check whether the answer exceeds the word limit, adds a fact or marks an unknown.

Specify the output shape

“Return a table” leaves open which columns to include. Name them. For JSON, provide the allowed fields and say whether additional fields are permitted. For code, identify the language version, files in scope and test command.

Instead of:

Return data problems as JSON.

try:

Return valid JSON only.
Each problem has: "row", "field", "reason", "suggested_fix".
Do not add fields.
If there are no problems, return an empty array.

Even a precise instruction does not guarantee valid JSON. Parse and validate model output in your application before using it.

Add an example when the rule is hard to describe

One example often helps with a house style, custom category or unusual format. Choose a case that exposes the difficult rule. If blank order IDs should be ignored, include one blank ID. If citations must appear beside factual claims, show the expected citation placement.

Examples can also mislead. Several nearly identical examples may cause a model to copy their wording instead of learning the intended rule. Start with one representative example and add another only when it resolves a real ambiguity.

OpenAI’s prompt engineering guide recommends clear instructions and examples for tasks that need a specific output. Anthropic’s prompt engineering overview covers examples and structured prompting for Claude. These are provider-specific documents, so check the model and API version you use.

Iterate on the failure you can see

When an answer misses, state the defect rather than asking it to “make the answer better”:

  • “Keep the structure. Reduce each paragraph to two sentences.”
  • “Remove facts that do not appear in the source.”
  • “Return only the JSON array. No preamble.”
  • “Compare options by price and compatibility. Do not rank brands.”

Each instruction names a result you can verify. For an important answer, compare a second model or check the source yourself. Confidence in the wording does not prove factual accuracy.

Choose the prompt language deliberately

Use the language of the intended output when it keeps the task clear. An English prompt is not automatically better for English code, and a Polish prompt is not a problem for a Polish email.

For mixed-language work, separate the instruction and output languages: “Review the English contract. Answer in English. Keep quoted source text unchanged.” That prevents the model from guessing which parts to translate.

Know when a prompt cannot solve the problem

A prompt cannot create missing facts, verify a current price or securely handle untrusted text by itself. If a task depends on external information, provide sources and check the result. If it runs inside an application, validate output and constrain tool access.

For API work, use a token budget and handle rate-limit errors. The API errors guide covers retries, context limits and usage logging.

FAQ

Should every prompt start with “act as an expert”?

No. State the task and the criteria first. Add a role only when it changes the vocabulary, perspective or evaluation rules.

How many examples should I provide?

Start with one example that demonstrates the difficult rule or output shape. Add another if the first leaves an important edge case unclear.

How can I reduce made-up facts?

Provide source material, tell the model to separate facts from inferences and specify what to do when information is missing. Verify dates, numbers and quotations yourself.

Does a longer prompt produce a better answer?

Only when the extra detail changes the task or criteria. Remove background that does not affect the output.

Sources