AI Prompt Engineering

Prompt engineering is how an application turns a user need into clear model input. It happens before the LLM request is tokenized. For what happens after text enters the model, see AI Fundamentals.

It is not about finding “magic words.” It is about clearly communicating the task, context, constraints, and expected output to the model.

This page builds one customer-support prompt from a vague request into a reusable input contract. The same approach applies to summarising, extracting, drafting, and many other LLM tasks.

1. Big picture: from task to better prompt

Start with the simplest clear prompt that can solve the task. Evaluate real outputs, then add only the missing piece: examples for consistency, constraints for boundaries, a reasoning technique for genuinely multi-step work, or a template for repeated use.

2. Build one prompt together

Our task is to classify this ticket:

My account was charged twice and I cannot log in.

2.1 Start naive

Classify this ticket:
"My account was charged twice and I cannot log in."

This leaves too much unspecified: what does “classify” mean, which labels are valid, and what should the result look like?

2.2 Define the task and allowed outputs

Classify the customer-support ticket.

Allowed categories:
- Urgent
- General Inquiry
- Feedback

Giving a closed label set makes the task testable and reduces format drift.

2.3 Add context, boundaries, and separate the data

Classify the customer-support ticket into one allowed category:
Urgent, General Inquiry, or Feedback.

Use only information contained in the ticket.
Do not invent missing information.

<ticket>
My account was charged twice and I cannot log in.
</ticket>

Clear delimiters keep the ticket as data, rather than letting it silently blend into the instructions. In an application, user input and retrieved text should not be trusted as instructions.

2.4 Define the output contract

Return valid JSON only:
{
  "category": "Urgent | General Inquiry | Feedback",
  "reason": "brief explanation grounded in the ticket"
}

Together, the reusable prompt is:

You classify customer-support tickets.

Task:
Classify the ticket into exactly one allowed category.

Allowed categories:
- Urgent
- General Inquiry
- Feedback

Rules:
- Use only information in the ticket.
- Do not invent missing information.

Current ticket:
<ticket>
My account was charged twice and I cannot log in.
</ticket>

Output contract:
Return valid JSON only:
{
  "category": "Urgent | General Inquiry | Feedback",
  "reason": "brief explanation grounded in the ticket"
}

The likely category is Urgent, but the important lesson is the construction process. The prompt states what to do, what information is available, the boundaries, and how success must be expressed.

3. Prompt anatomy: the reusable input contract

A useful prompt usually includes only the components the model needs:

Not every prompt needs every box. A short, clear zero-shot instruction is often best; add components only when the result needs them.

3.1 Roles and context management

A useful prompt is a controlled context budget, not a dump of every conversation message and document. Context-window mechanics are covered in AI Fundamentals.

4. Add examples only when clear instructions are not enough

A shot is an input → desired-output example inside the prompt. Examples demonstrate a pattern; they do not retrain the model or update its weights.

Technique What the prompt contains Best use
Zero-shot Instructions only; no examples A clear, familiar task where the format is simple.
One-shot One example A small formatting or classification cue.
Few-shot Several representative examples A task with a specific label set, tone, structure, or edge cases.

Zero-shot: start here

Classify this support ticket as Urgent, General Inquiry, or Feedback.

Ticket: "My account was charged twice and I cannot log in."
Answer:

One-shot: show one pattern

Classify each support ticket as Urgent, General Inquiry, or Feedback.

Ticket: "How do I change my email address?" → General Inquiry

Ticket: "My account was charged twice and I cannot log in." →

Few-shot: cover meaningful differences

Classify each ticket as Urgent, General Inquiry, or Feedback.

Ticket: "The checkout page is unavailable." → Urgent
Ticket: "How do I change my email address?" → General Inquiry
Ticket: "The new dashboard is much easier to use." → Feedback

Ticket: "My account was charged twice and I cannot log in." →

5. Improve boundaries and output reliability

Explicit constraints tell the model what to avoid. Pair them with a safe fallback, so the model knows what to do instead.

Use only the supplied product documentation.
Do not invent product features, prices, or citations.
If the documentation does not answer the question, say: "I don't have enough information."

For the ticket prompt, Use only information in the ticket and Do not invent missing information are the same idea. The output contract is another constraint: it specifies a shape the application can parse.

When an application needs machine-readable output, request a schema or use a provider’s structured-output feature. Valid syntax does not guarantee factual, safe, or authorized content.

6. Use reasoning techniques only for multi-step work

Chain-of-thought (CoT) prompting asks a model to break a multi-step problem into intermediate reasoning steps before answering. It is most useful for maths, constraint checking, and multi-step logic—not simple extraction or ticket classification.

Work through the calculation step by step. Check the result.
Then return only:
Answer: <number>

Question: A customer has $100, spends $20 and $40, then receives a $35 refund.
How much remains?

Two related forms:

CoT can improve difficult reasoning, but it increases latency and output-token cost. Do not treat a plausible written rationale as proof: validate calculations, policy decisions, and high-impact outputs with deterministic checks or authoritative tools. Some reasoning models use internal reasoning that is not fully returned to the user.

7. Turn a working prompt into a template

A prompt template keeps a repeatable structure while replacing variables at runtime:

Task:
Summarize the customer message in one sentence.

Rules:
- Preserve product names and error codes.
- Do not infer facts that are not present.

Customer message:
<message>

</message>

Output:
Summary:

8. Choose the simplest technique that fits

Start with a clear instruction
          ↓
Does it work reliably?
     YES → stop
     NO
          ↓
Need examples?             → One-shot / few-shot
Need stronger boundaries?  → Explicit constraints and a fallback
Need structured reasoning? → Appropriate reasoning technique
Repeated production task?  → Versioned prompt template

The progression is a decision process, not a requirement to use every technique:

Clear instruction → zero-shot → one-shot → few-shot → additional constraints / reasoning
Need Start with Escalate when needed
Clear task and simple format Zero-shot Add an output example.
Exact labels, tone, or layout One-shot or few-shot Improve representative examples.
Multi-step calculation or logic Zero-shot CoT Few-shot CoT or deterministic verification.
Avoid a type of claim or content Negative prompting plus a fallback Guardrails and application validation.
Repeated production use Versioned template and evaluation set Prompt management and controlled rollout.

9. Prompt engineering has clear limits

Prompt engineering guides model behaviour; it is not itself a security boundary.

Prompt engineering
CAN:
✓ Explain the task
✓ Provide context
✓ Set behavioural constraints
✓ Provide examples
✓ Define output format
✓ Improve consistency

DOES NOT GUARANTEE:
✗ Authorization
✗ Factual correctness
✗ Deterministic output
✗ Protection against every jailbreak
✗ Application-level security

Use guardrails, access control, input validation, and output/tool validation where those properties matter. This page focuses only on designing the prompt itself.

10. Practical checklist

11. Prompt injection and jailbreaking

Prompt injection

Prompt injection occurs when untrusted input contains instructions that attempt to change or override the application’s intended instructions.

The application intended the customer message to be data, but the model may interpret part of that data as instructions. This is why the earlier ticket prompt separates its parts:

Delimiters and a clear instruction hierarchy help guide the model, but they do not make prompt injection impossible. Prompt engineering is not a security boundary.

There are two common forms:

For example, an application could load a document or web page that contains Ignore previous instructions...; when that content enters the model context, it can try to alter the model’s behaviour.

Jailbreaking

A jailbreak is an attempt to get a model or application to bypass its intended behavioural or safety restrictions.

The concepts can overlap: a malicious user can use injection techniques as part of a jailbreak, but they are not synonyms.

Exam memory rule: Prompt injection = untrusted input tries to become instructions. Jailbreak = attempt to bypass intended restrictions.

12. Prompt engineering vs inference parameters

Prompt engineering changes what we tell the model. Inference parameters change how its generation/decoding behaves.

For example:

"Respond creatively and give several ideas."
        → Prompt instruction

temperature = 0.9
        → Inference configuration

They can influence similar observable behaviour, but operate at different layers. Temperature, top-p, top-k, logits, and sampling are explained in AI Fundamentals; support and permitted ranges depend on the chosen model/API.

13. Prompt management in Amazon Bedrock

Prompt management in Amazon Bedrock helps teams create, save, test, compare, version, and reuse prompts. It is useful when a prompt should be managed as a repeatable asset rather than embedded and edited separately throughout application code.

A prompt can include variables/placeholders that are supplied at runtime:

Summarize the following customer message:



Return the summary in:

For exam recognition, associate Bedrock Prompt management with reusable prompts, variables, prompt variants/testing, and versions. A version is a saved snapshot that can be used by an application after the draft has been iterated on.

14. Evaluate prompts against the actual objective

Prompt quality should be evaluated against what the application needs, not by how long or sophisticated the prompt looks. Useful dimensions include:

Prompt A
95% classification accuracy
500 input tokens

Prompt B
95% classification accuracy
120 input tokens

If other behaviour is equivalent,
Prompt B may be preferable for cost and latency.

Test representative inputs, including normal and edge cases, then refine the smallest part of the prompt that addresses the observed issue.

15. Exam recognition guide: if the question says X, think Y

If the scenario says… Think…
No examples are provided Zero-shot
One example is provided One-shot
Several examples demonstrate the task Few-shot
Break a multi-step problem into reasoning steps Chain-of-thought
Tell the model what it should not do Negative prompting / explicit constraint
Reusable prompt containing variables Prompt template
Untrusted input attempts to override application instructions Prompt injection
Malicious instruction hidden in external content Indirect prompt injection
User attempts to bypass intended model restrictions Jailbreaking
Change randomness/creativity during generation Temperature
Restrict generation by cumulative probability Top-p
Keep a fixed number of likely next-token candidates Generation top-k
Need reusable/versioned prompts in AWS Amazon Bedrock Prompt management
Need actual authorization or security enforcement Not prompt engineering

16. Final mental model

References

Contents