ONE MODEL, THREE LESSONS
Keep the experiment small enough to see what changes
This notebook uses Amazon Nova Lite through the Bedrock Runtime API. The model and question stay essentially the same while the request evolves in three deliberate steps: a zero-shot prompt, a prompt augmented with reference context, and a streamed invocation.
The example asks for the Krabby Patty recipe from SpongeBob SquarePants. That playful test makes an important failure mode obvious: a model can produce a polished answer even when the prompt gives it no authoritative facts.
Prompt quality is not only about wording. It is also about what evidence the model receives and how the application delivers the result.
ZERO-SHOT PROMPTING
First, ask the model without examples or supporting context
A zero-shot prompt gives the model a task but no worked example and no external reference material. The notebook assigns the role of cooking assistant and asks for a Krabby Patty recipe in one request.
prompt = """
You are a cooking assistant.
Explain how to cook the famous Krabby Patty.
"""
body = {
"messages": [{
"role": "user",
"content": [{"text": prompt}]
}],
"inferenceConfig": {
"maxTokens": 2048,
"temperature": 0,
"topP": 0.9
}
}Sure, let's dive into making a delicious "Crabby Patty"
inspired by SpongeBob SquarePants!
For the patty:
- 1 lb ground beef
- 1 cup breadcrumbs
- 1/2 cup finely chopped onion
- 1/2 cup finely chopped bell pepper
- 1 egg
- Worcestershire sauce and Dijon mustard
- Old Bay seasoning
Form four patties and cook them in a skillet or grill pan
for 4–5 minutes on each side. Toast conventional hamburger
buns, then add lettuce, tomato, pickles, ketchup, mustard,
and mayonnaise.The response is fluent and complete, but it invents a conventional burger recipe instead of following the established Krabby Patty details. That is the useful lesson: zero-shot does not mean grounded. The model can follow the shape of the task while filling missing facts from patterns learned during training.
CONTEXT AUGMENTATION
Give the model the facts it should use—and define the boundary
The second request adds a compact reference block containing the permitted Krabby Patty ingredients and the single cooking instruction. It also tells the model to use only that material and specifies the desired output shape.
This is context augmentation in its simplest form. The application supplies relevant information at request time; the model is not retrained, and the reference text does not become part of its permanent knowledge.
role = """
You are a cooking assistant. Explain how to cook the famous
Krabby Patty popularized by SpongeBob SquarePants.
"""
question = "How do you cook the famous Krabby Patty?"
context = """
Use these reference facts for the Krabby Patty.
Secret formula ingredients:
- Flour for the seaweed buns
- Barnacle shavings
- Salt and turmeric
- Seaweed paste
- Sea horseradish sauce
- Chum from the original recipe
- Chili peppers, liquid smoke, and breadcrumbs
Toppings:
- Seaweed buns
- Veggie patty
- Sea lettuce and sea cheese
- Sea onion and sea tomato
- Sea ketchup and sea mustard
- Sea pickles
Cooking instruction: Cook it with love.
"""
augmented_prompt = f"""
{role}
Use only the following reference for the ingredients:
<context>
{context}
</context>
Question: {question}
Answer: List only the Krabby Patty ingredients and the one cooking instruction.
"""### Ingredients for the Krabby Patty
The Secret Formula:
- Flour for the seaweed buns
- Barnacle shavings
- Salt and turmeric
- Seaweed paste
- Sea horseradish sauce
- Chum from the original recipe
- Chili peppers, liquid smoke, and breadcrumbs
Toppings:
- Seaweed buns
- Veggie patty
- Sea lettuce and sea cheese
- Sea onion and sea tomato
- Sea ketchup and sea mustard
- Sea pickles
### Cooking Instruction
- Cook it with love.The result now stays inside the supplied reference and ends with the requested instruction. The improvement comes from three controls working together: relevant context, an explicit source boundary, and a precise output contract.
BEDROCK RUNTIME
Send the Nova message envelope through Boto3
Nova Lite expects a message-shaped request body. The notebook keeps formatting and response parsing in small helper functions so the experiment can focus on the prompt rather than the transport details.
import json
import boto3
bedrock = boto3.client("bedrock-runtime")
response = bedrock.invoke_model(
modelId="amazon.nova-lite-v1:0",
body=json.dumps(format_for_nova_lite(augmented_prompt)),
accept="application/json",
contentType="application/json",
)
payload = json.loads(response["body"].read())
answer = parse_nova_lite_response(payload)invoke_model waits for the complete response body. That is convenient for batch work and short answers, but an interactive interface can feel idle while the model is generating.
STREAMING OUTPUT
Render each text delta instead of waiting for the final document
The streaming request keeps the same model, prompt, and generation settings. Only the invocation method and response handling change. Bedrock emits events; Nova text arrives inside contentBlockDelta records.
response = bedrock.invoke_model_with_response_stream(
modelId="amazon.nova-lite-v1:0",
body=json.dumps(format_for_nova_lite(augmented_prompt)),
accept="application/json",
contentType="application/json",
)
parts = []
for event in response["body"]:
chunk = event.get("chunk")
if not chunk:
continue
message = json.loads(chunk["bytes"].decode())
delta = message.get("contentBlockDelta", {}).get("delta", {})
text = delta.get("text", "")
parts.append(text)
update_display(Markdown("".join(parts)), display_id=display_id)Streaming improves perceived responsiveness because the reader sees useful text as soon as it is available. It does not make the model more accurate; grounding still comes from the augmented prompt and the quality of its context.
THE PATTERN
Separate the three decisions in your own application
- Zero-shot prompting defines the task with no demonstrations. Use it to establish a baseline and expose what the model assumes.
- Context augmentation supplies application-owned evidence at request time. Delimit the context and tell the model how it may use it.
- Streaming output changes delivery, not reasoning. Accumulate deltas for the final answer while rendering them incrementally for the user.
Baseline the behavior. Add the evidence. Then improve the experience.
SOURCE MATERIAL