Prompt engineering is the practice of designing input interfaces for large language models. It translates human goals, business context, and output requirements into instructions a model can execute consistently, then uses tests to verify the results.
A useful prompt usually contains a task, context, constraints, examples, and an output format. Production use adds version control, evaluation datasets, failure handling, and safety boundaries. Together, these parts determine whether a model can produce acceptable results across different inputs.
What is prompt engineering?
A large language model receives a context and predicts the most suitable continuation. Prompt engineering organizes that context so the model has the information required to complete a task.
From a software engineering perspective, a prompt resembles a function interface:
instruction defines the task, context supplies knowledge, constraints set boundaries, examples demonstrate a pattern, and outputSchema establishes the contract between the model and downstream software.
Prompt engineering commonly covers four areas:
- Design: convert an ambiguous request into explicit instructions.
- Orchestration: divide complex work and coordinate model, retrieval, and tool calls.
- Evaluation: measure accuracy, format compliance, and consistency with representative samples.
- Maintenance: version prompts, models, and parameters, then run regression tests.
Why does prompt engineering exist?
Natural language often omits assumptions. People fill those gaps through shared experience, while a model infers them from the current context. A request such as “analyze this” could mean finding a root cause, extracting a summary, comparing options, or generating an action plan.
Large language models are probabilistic. Changes to the model, sampling parameters, or input can change the result. Prompt engineering keeps that variation within acceptable limits by clarifying the goal, narrowing the search space, and defining acceptance criteria.
It addresses three recurring engineering problems:
| Engineering problem | Treatment in the prompt |
|---|---|
| Human goals contain implicit conditions | Define the task, reader, purpose, and success criteria |
| Model knowledge has a boundary | Supply context, retrieved material, time ranges, and sources |
| Generated output varies | Fix the format, add examples, evaluate, and run regression tests |
Prompt quality therefore depends on executability and verifiability. Plain language works well when the essential fields are complete.
What problems does it solve?
Aligning the task with its purpose
“Summarize this incident report” leaves the intended use unclear. An on-call engineer needs a timeline and mitigations, management needs impact and risk, and the development team needs a root cause and repair plan. Defining the reader and purpose helps the model choose the right information density and structure.
Supplying required context
Internal documents, live databases, and the current page must reach the model through context or tools. A prompt can carry that material directly or receive content from a retrieval system. Once the model has a factual boundary, its answer can cite evidence from the input.
Fixing the output contract
When software consumes the result, the output format becomes an interface protocol. JSON Schema, enumerated values, and required fields reduce parsing failures and make field-level validation possible.
Dividing complex tasks
A complex task works better as several verifiable stages. A technology assessment, for example, can be divided into requirement extraction, candidate screening, evidence review, risk analysis, and recommendation. Each stage has a clear input and output, which makes failures easier to locate.
Creating repeatable quality standards
The prompt, model version, parameters, and evaluation set form a reproducible experiment. A team can compare accuracy, latency, cost, and format compliance across two versions before selecting one.
Who uses it, and where?
Individuals can use prompts to improve a single conversation. Development teams working with recurring tasks, programmatic calls, and shared workflows add templates, version control, and automated evaluation.
| User | Common scenarios | Primary concerns |
|---|---|---|
| Developers | Code generation, tests, log analysis, agent tool calls | Output format, permission boundaries, regression tests |
| Data teams | Extraction, classification, entity recognition, reports | Accuracy, schema compliance, batch cost |
| Research and operations | Evidence synthesis, market analysis, internal Q&A | Sources, recency, factual consistency |
| Content and product teams | Technical articles, product documentation, support replies | Reader, tone, brand rules |
Recurring execution, downstream software, and costly errors all justify treating prompts as engineering interfaces. A one-off exploration can begin with a short instruction and gain context or constraints as failures reveal missing information.
How to design a prompt
Define the result first
Start with the deliverable and its success criteria, then add the role and background. A useful task description answers three questions: what should the model produce, who will use it, and which decision will it support?
Supply essential context
Context includes facts, terminology, environment, time range, and sources. Put long materials inside explicit delimiters so instructions and data have clear boundaries.
State verifiable constraints
Constraints define evidence sources, time ranges, tool permissions, and response boundaries. Each constraint should support a concrete check.
“Analyze accurately” is subjective. “Cite evidence for every conclusion” supports automated validation or human review.
Demonstrate the pattern with examples
Examples are useful for special taxonomies, fixed writing styles, and boundary cases. A good example set covers normal cases and inputs that are easy to confuse.
Define the output format and checks
Structured output suits machine consumption, while Markdown suits human readers. A final check verifies fields, evidence, and constraints.
A complete example
This template contains a role, objective, context, rules, output contract, and quality check. These six fields provide a useful starting point for most technical tasks.
Common prompt frameworks and structures
Prompt frameworks are mnemonic templates for essential fields. Four structures cover a broad range of tasks: RTF for short tasks, STAR for analytical flow, CO-STAR for communication, and RODES for technical work with explicit quality checks.
RTF: a compact structure
RTF stands for Role, Task, and Format. It suits summaries, rewriting, classification, and format conversion.
RTF is short and inexpensive to maintain. Tasks involving private knowledge, multiple steps, or strict quality criteria can add Context, Examples, and Check fields.
STAR: organizing an analysis
STAR stands for Situation, Task, Action, and Result. It comes from structured case presentation and also works well for incident reviews, problem analysis, and scenario planning.
STAR preserves the causal chain from context through action to result, which helps technical tasks explain their analytical basis.
CO-STAR: controlling communication
CO-STAR stands for Context, Objective, Style, Tone, Audience, and Response. The framework was demonstrated systematically during Singapore’s 2023 GPT-4 prompt engineering competition. It suits technical articles, product explanations, and communication for a defined audience.
Style, Tone, and Audience adapt the same technical material to different readers.
RODES: adding examples and a quality check
RODES stands for Role, Objective, Details, Examples, and Sense Check. It suits code review, technical research, and tasks that require a final review.
RODES puts examples and a final check directly into the structure, making it useful for technical tasks that require consistent output.
How to choose a framework
Clarify the goal, input material, main risk, and output consumer. Then choose the smallest structure that covers those requirements.
| Scenario | Recommended structure | Reason |
|---|---|---|
| One-off short task | RTF | Few fields and low maintenance cost |
| Incident review or case analysis | STAR | Preserves causality between context, action, and result |
| Writing for a defined audience | CO-STAR | Controls style, tone, audience, and response shape |
| Research, review, or technology selection | RODES | Includes examples and a final quality check |
Structures can be combined. For example, use STAR to organize an incident’s causal chain, then use RODES to add constraints, reference examples, and a final check.
After choosing a structure, check three questions:
- Does the primary failure risk come from missing knowledge, execution steps, or output format?
- Which fields support programmatic validation?
- Which inputs belong in a regression evaluation set?
How to evaluate prompts
Prompt evaluation fixes the model, parameters, prompt version, and test data. A single successful output verifies one sample, while an evaluation set measures overall quality.
Build an evaluation set
An evaluation set should represent the major types of production traffic:
- Normal inputs verify the main task.
- Boundary inputs cover empty values, long text, and extreme numbers.
- Ambiguous inputs verify that the model marks missing information.
- Adversarial inputs test whether instructions inside external material interfere with system rules.
- Historical failures protect previous fixes from regression.
Each case should contain an input, expected characteristics, and scoring rules. Classification tasks can store reference labels, while open-ended tasks can use a rubric.
Choose metrics
| Dimension | Example metrics |
|---|---|
| Task quality | Accuracy, recall, factual consistency, human rating |
| Format quality | Schema pass rate, required-field completeness, parse success rate |
| Consistency | Agreement across repeated runs, regression pass rate |
| Performance | P50/P95 latency, input and output token counts |
| Cost | Cost per call, average cost per acceptable result |
| Safety | Privilege-violation rate, prompt-injection success rate, sensitive-data exposure rate |
Deterministic checks suit structured tasks. Open-ended tasks can combine rules, model-based scoring, and human sampling. A model-based grader needs its own validation and a human-labeled calibration set.
Compare versions
Change one main variable in each experiment, such as prompt wording, examples, model version, or sampling parameters.
A candidate version should meet predefined quality, safety, latency, and cost criteria. Add newly discovered failure cases to the evaluation set.
Set acceptance criteria
A technical analysis prompt could use criteria like these:
Set concrete values from business risk and baseline results. High-risk use cases also require access control, human approval, audit logs, and deterministic validation.
Practical checklist
- The task, reader, and success criteria are explicit.
- Context includes sources, time ranges, and required terminology.
- Instructions and external data use clear delimiters.
- Constraints support programmatic or human checks.
- The output format matches its downstream consumer.
- Examples cover normal cases and critical boundaries.
- Missing information and inferences have explicit labels.
- Prompt, model, and parameter versions are recorded.
- The evaluation set contains real and historical failure samples.
- Acceptance criteria cover quality, performance, cost, and safety.
The main result of prompt engineering is a maintainable model interface: explicit requirements, bounded input, contracted output, and measurable quality.
References
- Brown et al., Language Models are Few-Shot Learners, 2020.
- Wei et al., Chain-of-Thought Prompting Elicits Reasoning in Large Language Models, 2022.
- Yao et al., ReAct: Synergizing Reasoning and Acting in Language Models, 2022.
- White et al., A Prompt Pattern Catalog to Enhance Prompt Engineering with ChatGPT, 2023.
- Sheila Teo, How I Won Singapore’s GPT-4 Prompt Engineering Competition, 2023.
- Twisted Brackets, Riding the Wave of Effective AI Prompt Crafting, 2023.