Full Stack & AI · Day 04 · Chapter 03

Prompt
Engineering

A prompt is the request-time context that specifies a task for an LLM.

It does not give the model new parameters. It determines what the model can condition on for this response.

instructionsevidenceexamplescurrent task
Pre-traininglearns broad language patterns
↓
Prompt at request timesupplies task, evidence, examples, constraints
↓
Conditioned outputthe response follows this assembled context
The prompt as an interface

Make the task contract
inspectable.

A real application prompt is assembled from distinct components. Separating them makes ambiguity, evidence boundaries, and failure behaviour reviewable.

TaskExtract assessable course outcomes from the supplied syllabus.
Evidence boundaryUse only the syllabus. Do not infer an outcome that is not stated.
ConstraintsPreserve source wording. Flag ambiguity instead of forcing a label.
Output contractReturn JSON with an evidence span and needs_review.
ExamplesShow difficult boundaries only when the specification is not enough.
The model sees tokens, not your unstated intention.
Long context is position-sensitive

Inside the window
does not mean equally used.

Critical evidence can be present but hard for a model to use when it is buried in a long prompt.

Place stable rules clearly; keep evidence close to the task that needs it; test equivalent prompts with the evidence moved.

Prompt sequence
Stable instructions
Critical evidence
“CO3 requires application-level questions”
Background notes
Current request
“Create five questions”
Beginning: evidence is prominent, but separated from the immediate task.
Prompt consolidation

Preserve the signal.
Remove the scatter.

As a task grows, consolidate repeated instructions, selected evidence, and decisions into one canonical context record.

Scattered context

“Use a rubric.”
old chat: “Output JSON.”
retrieved policy: 14 pages
“Don’t infer missing outcomes.”
repeated style instructions
→

Canonical context record

RequirementsExtract only stated outcomes; JSON schema.
Selected evidenceClauses 2.1, 2.4, 5.3 with source IDs.
DecisionsUse Bloom level only when explicit.
Open issueOutcome 4 remains ambiguous → review.

Consolidation reduces token cost and distraction. It can also lose exceptions—keep original sources available and never promote instructions inside untrusted documents.

Low-resource language prompting

Use the target language
as a testable choice.

Target-language prompts and examples can preserve terminology, grammar, and local meaning. They are not automatically better than English for every model.

Target-language specification

TASK
താഴെയുള്ള വിദ്യാർത്ഥി പ്രതികരണത്തെ
"ശരിയാണ്", "ഭാഗികം", അല്ലെങ്കിൽ
"തെളിവില്ല" എന്ന് ലേബൽ ചെയ്യുക.

OUTPUT
{"label":"...", "evidence":"..."}

What to evaluate

Does a target-language instruction and demonstration improve label fidelity for your intended users?

Or does the model follow English instructions more reliably while still producing the target language?

1
Target instruction
+ target examples
2
English instruction
+ target data
3
Translated prompt
4
Language-native evaluation set
In-context learning

Examples specify a local
mapping.

Zero-shot gives the task and input. Few-shot also shows representative input–output demonstrations. Neither updates the model’s parameters.

Zero-shot

TASK: Classify the outcome as assessable or needs review.

INPUT: “Exposure to cloud-native systems.”

Use when the task and output are easy to state.

→

Few-shot

EXAMPLE
“Implement and test a REST API.”
→ assessable

EXAMPLE
“Exposure to cloud-native systems.”
→ needs_review

NOW: {{OUTCOME}}

Use when a boundary or label meaning is hard to express abstractly.

Reasoning scaffolds and actions

Choose a technique to resolve
a known failure.

For a multi-step transformation, intermediate artefacts can make work checkable. When facts are missing, a tool observation can ground the next step.

Chain of thought

Useful for hard multi-step tasks when intermediate work can be verified.

Extract
Identify stated CO3 constraints.
↓
Plan
Select an application-level question form.
↓
Check
Verify outcome alignment before drafting.

A fluent trace is not proof. Prefer inspectable facts, calculations, and plans.

ReAct

Reason → Act → Observation. Use when the task needs current external evidence or controlled computation.

Reason
“I need the official moderation rule.”
↓
Act
search_policy("moderation")
↓
Observe
Retrieved clause 4.2 becomes data for the next step.

Validate tool arguments and require approval for consequential actions.

Technique selection

Do not add a technique
without a measurable reason.

Technique
Failure it addresses
What must be checked
Structured prompt
Ambiguous task or format
Schema and output contract
Few-shot examples
Unclear labels or edge cases
Representative examples, not imitation
CoT / plan-and-check
Multi-step transformation
Intermediate artefact is verifiable
Retrieval / ReAct
Missing or stale facts
Source quality, tool scope, permissions
Self-consistency
Several plausible solution paths
Aggregation rule and extra cost
Synthesis

A prompt is a
runtime contract.

The techniques in this chapter refine the same request-time contract: task, constraints, evidence, and required output.

<task>
{{ONE CLEAR TRANSFORMATION}}
</task>

<constraints>
{{SCOPE, EXCLUSIONS, AND FAILURE BEHAVIOUR}}
</constraints>

<evidence>
{{DELIBERATELY DELIMITED INPUT WITH SOURCE IDS}}
</evidence>

<output_contract>
{{SCHEMA, LENGTH, AND REQUIRED EVIDENCE}}
</output_contract>

Add examples, consolidation, retrieval, tools, or fine-tuning only when evaluation shows the added complexity is justified.

Prompt engineering is experimental engineering

Version the prompt.
Measure the workflow.

One impressive response is not evidence of reliability. Compare prompt changes on a fixed, representative evaluation set.

HypothesisWhich ambiguity are we removing?
→
Prompt versionmodel + context + decoding config
→
Test setnormal, ambiguous, adversarial cases
→
Evaluatequality · safety · cost · latency
Continue the narrative

Next: Hands-on with LLMs

We will apply these ideas to real model interactions: baseline prompt, structured prompt, evidence-grounded prompt, and evaluation.

Open Chapter 04 →

Research: Lost in the Middle · multilingual few-shot learning · Chain of Thought · ReAct