Skip to main content
This lesson demonstrates how adding structure, constraints, and examples to your prompts yields more consistent, reliable outputs. We’ll show a compact JSON schema you can require the model to return, provide few-shot examples, and present a runnable Python example for Amazon Bedrock. Use these patterns to reduce ambiguity and speed iterations.
Use a clear role, a strict output format, and representative examples. These three elements combined make prompts much more predictable and easier to integrate into applications.

Required output format

Require the model to return only valid JSON in this exact structure:
Enforcing a strict schema like this reduces parsing errors and simplifies downstream automation.
Always validate the model output as JSON before consuming it in production. If the model returns invalid JSON, fail safely and retry with clearer constraints.

Few-shot examples

Providing a couple of representative examples (few-shot) helps the model map free-text tickets to the structured fields you expect. Example 1 — Billing ticket:
Example 2 — Security ticket:
New ticket to classify:
Expected machine-readable output (example):

Why this works

  • Role + constraints + examples reduces ambiguity and narrows the model’s output distribution.
  • A fixed schema simplifies parsing and downstream routing.
  • Few-shot examples teach the mapping from natural language to structured fields.

Prompt components (quick reference)

Practical Python example (Amazon Bedrock)

Below is a compact Python snippet illustrating how to send the prompt to Bedrock (adjust the API call to your SDK version). The core idea is to send the role + prompt and then parse the returned text as JSON.
Example console run (cleaned):

What to expect from iterative prompt engineering

  • More consistent outputs as you refine role and examples
  • Faster integration because the model produces predictable, structured responses
  • Reusable prompt templates that work across use cases once tuned
Key takeaway: prompt engineering is an iterative discipline. Start with a role, define a strict output format, add diverse examples, validate outputs, and iterate.
A presentation slide titled "Key Takeaway." It states that prompt engineering is the process of structuring and refining prompts so models produce more reliable and useful results.
You have your prompt, inspect the result, address weaknesses, and iterate. Each refinement should yield stronger, more consistent outputs. This wraps up this short lesson on prompt engineering. Try these techniques in a hands-on lab to practice and reinforce the concepts.
A presentation slide titled "What's Next?" with the subtitle "Practicing various prompt engineering techniques LAB." On the right is a teal circular icon showing a stylized brain merged with circuit lines.
  • Amazon Bedrock documentation
  • Bedrock SDK reference: check your SDK’s method names for “converse”, “invoke_model”, or equivalent.

Watch Video

Practice Lab