Text editor showing a structured system prompt with annotations

What is Prompt Engineering?

AGAI 103 · Foundations of Prompting

Understand what prompt engineering is, why prompts affect model behavior, and how to design prompts as testable instructions for LLM-powered systems.

Learning objectives

  • Define prompt engineering as a practical development discipline.
  • Identify the major layers of a prompt.
  • Explain how phrasing, examples, and sampling parameters influence output.
  • Compare zero-shot, one-shot, and few-shot prompting.
  • Apply an iterative workflow for prompt development.

Prompt engineering is the practice of designing instructions, examples, context, and constraints so that a language model produces useful, reliable, and appropriately formatted outputs.

At first, prompting can look like ordinary writing. You type a request, the model answers, and the interaction feels conversational. But in production systems, prompts are closer to software interfaces. A prompt defines what the model should do, what it should avoid, what information it should use, and what shape the output should take.

Prompts matter because language models are sensitive to wording, ordering, examples, and context. Small changes can produce large differences in output. A vague prompt may produce a vague answer. A precise prompt with examples and constraints can produce a much more reliable result.

A useful way to think about an LLM is not as a database or a calculator, but as a highly capable, well-read person who is trying to infer what kind of answer you want from the text you provide. If the instructions are ambiguous, the model fills in the gaps using patterns from training. Prompt engineering reduces ambiguity.

Most prompts have three layers:

  1. System instructions — high-level behavior, role, boundaries, and style.
  2. Examples or demonstrations — sample inputs and outputs that show the pattern.
  3. User request — the specific task to complete now.

The best prompts align these layers. The system instruction defines the job. The examples demonstrate the expected behavior. The user request supplies the current task.

Before and after: why phrasing matters

Consider a vague prompt:

Summarize this article.

A model may produce a long summary, a short summary, a bullet list, an opinionated summary, or a generic overview. It has to guess what “summarize” means.

A stronger version is:

Summarize the article for a busy software engineering manager.
Use exactly 5 bullet points.
Focus on technical decisions, risks, deadlines, and business impact.
Do not include background details unless they affect execution.

The task is now clearer. The audience is defined. The format is constrained. The relevance criteria are explicit.

Another example:

Write a product description for this feature.

Improved:

Write a product description for a B2B SaaS feature.
Audience: operations managers at mid-sized companies.
Tone: clear, practical, not hype-driven.
Length: 120–160 words.
Include: the problem, the feature, the business benefit, and one concrete example.
Avoid: buzzwords, exaggerated claims, and technical implementation details.

The improved prompt behaves more like a specification. Good prompt engineering often means replacing implicit expectations with explicit constraints.

Temperature and top-p

Prompt design controls what the model is asked to do. Sampling parameters control how the model chooses among possible outputs.

Temperature affects randomness. Lower temperature makes the model more deterministic and conservative. Higher temperature makes outputs more varied and creative.

Typical guidance:

temperature = 0.0–0.3: extraction, classification, structured output, deterministic tasks
temperature = 0.4–0.7: general writing, explanation, summarization
temperature = 0.8–1.2: brainstorming, creative writing, divergent ideas

Top-p, also called nucleus sampling, limits the model to a subset of likely next tokens whose cumulative probability reaches a threshold. For example, top_p = 0.9 means the model samples from the smallest set of likely tokens that together represent 90% of probability mass.

Temperature and top-p both affect randomness, so it is usually best not to aggressively tune both at once. For structured production tasks, keep randomness low and rely on prompt clarity. For creative exploration, allow more randomness and evaluate outputs afterward.

Prompt design and sampling interact. A weak prompt with high temperature often produces unstable results. A strong prompt with low temperature is better for repeatable workflows.

Zero-shot, one-shot, and few-shot prompting

Zero-shot prompting gives instructions but no examples.

Classify the sentiment of this review as Positive, Neutral, or Negative.
Review: "The setup was confusing, but the product works well now."

Zero-shot prompting is simple and works well when the task is common and the format is easy.

One-shot prompting gives one example.

Classify the sentiment as Positive, Neutral, or Negative.

Example:
Review: "Fast shipping and excellent quality."
Sentiment: Positive

Now classify:
Review: "The setup was confusing, but the product works well now."
Sentiment:

The example shows the expected input-output pattern.

Few-shot prompting gives multiple examples.

Classify the sentiment as Positive, Neutral, or Negative.

Review: "Fast shipping and excellent quality."
Sentiment: Positive

Review: "The app crashed three times and support never replied."
Sentiment: Negative

Review: "It arrived on time. Nothing special, but it works."
Sentiment: Neutral

Review: "The setup was confusing, but the product works well now."
Sentiment:

Few-shot prompting is useful when the task has subtle categories, edge cases, or a specialized style. The model learns the pattern from the examples in the prompt without changing its underlying weights.

Prompt engineering as a professional skill

Prompt engineering is increasingly part of professional AI application development. Job titles and responsibilities may include AI engineer, prompt engineer, LLM application developer, conversational AI designer, AI product engineer, automation engineer, and agentic workflow designer.

In practice, prompt engineering appears in many use cases:

  • Customer support response drafting
  • Legal and policy document summarization
  • Code generation and review
  • Data extraction from unstructured text
  • Sales and marketing content generation
  • Internal knowledge-base assistants
  • Research assistants
  • Agentic workflow automation
  • Evaluation and red-teaming

The professional skill is not merely “knowing magic words.” It is the ability to translate a business or technical goal into a reliable model interaction. That includes prompt structure, examples, context selection, output validation, failure handling, and evaluation.

Prompt development is iterative

Treat prompts like code. You rarely write the perfect prompt on the first try. You draft, test, inspect failures, revise, and test again.

A practical prompt development loop:

1. Define the task and success criteria.
2. Write a first prompt.
3. Test on realistic examples.
4. Collect failure cases.
5. Revise instructions, examples, or output format.
6. Test again on old and new examples.
7. Add automated checks where possible.
8. Version the prompt before deployment.

For example, if a data extraction prompt misses dates written as “next Friday,” add an example with a relative date. If a summarization prompt includes irrelevant background, add explicit relevance criteria. If a JSON prompt sometimes returns invalid JSON, move to JSON mode or function calling.

Production prompt engineering requires test sets. A prompt that works on one example may fail on edge cases. Build a small library of representative inputs: easy cases, ambiguous cases, adversarial cases, long inputs, short inputs, malformed inputs, and cases where the model should refuse or ask for clarification.

Example API-style prompt structure

A basic chat request often separates system and user messages:

{
  "model": "example-llm",
  "temperature": 0.2,
  "messages": [
    {
      "role": "system",
      "content": "You are a technical writing assistant. Produce clear, concise, accurate explanations for software developers. If information is missing, state the assumption instead of inventing details."
    },
    {
      "role": "user",
      "content": "Explain rate limiting in REST APIs in 150 words."
    }
  ]
}

The system message sets durable behavior. The user message gives the current task. The low temperature supports consistency.

Checklist for a first prompt

Before using a prompt seriously, check the following:

Goal: Is the task clearly stated?
Audience: Does the model know who the answer is for?
Context: Did you provide the information it needs?
Constraints: Did you specify length, tone, format, or boundaries?
Examples: Would one or more examples reduce ambiguity?
Output: Is the desired structure explicit?
Uncertainty: Did you tell the model what to do when information is missing?
Safety: Are there actions or claims it should avoid?
Evaluation: Do you have test cases to verify the prompt works?

Prompt engineering is the discipline of turning intention into reliable model behavior. Good prompts are not just clever sentences. They are small, testable designs for human-AI collaboration.

Sign in to track your progress.

Ask your AI guide

AI Chat· Prompt Engineering — What is Prompt Engineering?
🤖

Ask anything about Prompt Engineering — What is Prompt Engineering?, or choose a suggested question below.

AI responses are educational and may not be perfectly accurate. Press Enter to send, Shift+Enter for new line.