Prompt engineering: design prompts from goals through evaluation
Prompt engineering is the process of specifying a language model’s task, the context it needs, the conditions it must follow, and the form of the result, then testing and refining that input on real cases. A well-designed prompt makes the task clearer, but it cannot guarantee truth or identical results across models. Defining success and checking outputs matter more than finding a magic phrase.
Prompt engineering: design prompts from goals through evaluation
Prompt engineering is the process of specifying a language model’s task, the context it needs, the conditions it must follow, and the form of the result, then testing and refining that input on real cases. A well-designed prompt makes the task clearer, but it cannot guarantee truth or identical results across models. Defining success and checking outputs matter more than finding a magic phrase.
What goes into a prompt?
A prompt may be one short question or a structured input containing role-based messages, source material, examples, tool instructions, and an output format. APIs may place these elements in roles such as system, developer, and user, or in separate fields. Role names and priority rules vary by service, so check the documentation for the model you use instead of assuming one provider’s format applies everywhere.
| Component | Question it answers | Example |
|---|---|---|
| Goal and task | What should the model finish? | Draft a reply to a customer’s refund question. |
| Context and evidence | Which information may it use? | Use only the refund policy provided below. |
| Constraints and exceptions | What must it avoid, and what if information is missing? | Do not guess deadlines or exceptions that are absent from the source; say they need confirmation. |
| Output contract | What format and required fields should the result have? | Return a draft reply, the supporting sentence, and any point that needs confirmation. |
| Examples | Would input/output pairs clarify the desired pattern? | Add examples when edge cases or a particular classification rule need to be demonstrated. |
You do not need to spell out every component at length each time. A simple transformation may need only the task and output format. Work that relies on multiple sources or feeds results to software benefits from more explicit context, constraints, and a schema. Examples can clarify an instruction, but examples that contradict the instruction can make behavior less predictable.
Make a request testable
The following is a hypothetical customer-support example. The policy text and reply do not represent a real company’s rules or a model test result.
A vague request might say, “Summarize the refund policy and answer the customer.” It leaves the evidence, missing-information behavior, and reply format open. A more specific prompt could be:
Task: Draft a reply to the customer's refund question.
Evidence: Use only policy statements inside the <policy> tags.
Rules: Do not guess deadlines, country-specific exceptions, or product-condition rules
that are not in the source. If information is missing, say “Not stated in the source.”
Output: 1) Draft reply 2) Supporting policy sentence 3) Follow-up information needed
Question: Can I return an item 20 days after delivery?
<policy>
Refunds may be requested within 30 days after delivery.
</policy>This version narrows the evidence, defines what to do when information is missing, and leaves support for a reviewer to inspect. Given only the hypothetical policy, a draft could say: “Yes. The provided policy allows a refund request within 30 days after delivery.” In a real system, the policy’s source and freshness, as well as any other conditions relevant to the question, still need checking.
How to improve prompts iteratively
**Turn success into observable criteria.** Replace “a good answer” with checks such as including required fields, using only allowed labels, or avoiding unsupported figures.
**Build representative test inputs.** Include ordinary cases and likely failures: empty input, boundary values, ambiguous wording, and conflicting sources. Check whether the test set represents the actual use case.
**Keep the baseline and results.** Record the model version, relevant settings, prompt version, test inputs, and outputs so you can compare changes. Re-evaluate after changing a model or API rather than assuming old results still apply.
**Classify failures and change one key factor at a time.** Missing context, vague instructions, invalid formatting, and distorted evidence are different problems. Changing many things at once makes the cause of an improvement hard to identify.
**Run regression checks and human review before release.** A schema validator can tell whether JSON parses; it cannot establish whether the content is true. Higher-impact work needs a way to inspect evidence and obtain approval.
The goal is not to obtain a perfect answer every time. It is to find recurring failures and check whether a change actually improves them. Google’s prompt-design guide emphasizes defining objectives and expected outcomes, then testing and evaluating systematically. OpenAI’s documentation notes that model outputs are non-deterministic and prompting methods can vary by model type or snapshot; it recommends evaluating prompts as they change.
What prompting cannot solve by itself
Prompt engineering changes the input conditions; it does not itself update model weights. If a system must use a fixed body of material, retrieval-augmented generation (RAG) can fetch trusted documents and add them to the input. If repeated behavior needs to be learned, fine-tuning may be an option. Choose based on the error pattern, how often source material changes, evaluation results, and operating cost.
Even clear instructions cannot prevent a model from inventing support or breaking a format. If software consumes the result, use schema validation and error handling; if the answer makes factual claims, check them against the source. Retrieved documents and webpages can contain instructions intended to manipulate the model. Separating such material and testing with adversarial inputs can help, but prompt wording alone cannot eliminate the risk. Give tool-using models only the permissions they need, and require human approval for consequential actions. Prompt engineering does not replace these security controls or verification.
References
[OpenAI API: Prompt engineering](https://developers.openai.com/api/docs/guides/prompt-engineering)
[Google Cloud: Overview of prompting strategies](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/prompts/prompt-design-strategies)
[Liu et al., Pre-train, Prompt, and Predict: A Systematic Survey of Prompting Methods in NLP](https://arxiv.org/abs/2107.13586)
[OWASP GenAI Security Project: LLM01:2025 Prompt Injection](https://genai.owasp.org/llmrisk/llm01-prompt-injection/)