Skip to content
Module 06 of 1250 min readBeginner

Prompt engineering for analysis

The techniques that actually work: role, context, examples, step-by-step reasoning, and structured output.

50%

Listen along

Read “Prompt engineering for analysis” aloud

Plays in your browser using on-device text-to-speech — nothing leaves the page.

Learning objectives

By the end of this module, you should be able to:

  • 01Structure a prompt with role, context, task, format, and constraints
  • 02Use few-shot examples and chain-of-thought to lift performance
  • 03Recognise the patterns that make prompts brittle (long, ambiguous, contradictory)
  • 04Apply structured-output and JSON-mode techniques for downstream parsing

A prompt is a function call. You wouldn't expect a function with vague arguments to return what you want; the same goes for LLMs. The discipline of prompting is the discipline of being specific.

The five-block structure

Most good prompts include some or all of these blocks, in order:

  • Role: 'You are an experienced equity-research analyst.'
  • Context: relevant background, data, or documents the model needs to do the task
  • Task: a clear, specific instruction. 'Summarise this 10-K filing in five bullet points focused on revenue concentration risk.'
  • Format: how the output should be structured. 'Return as JSON with keys ...'
  • Constraints: what the model should and shouldn't do. 'Cite specific page numbers. Don't speculate beyond the filing.'

Few-shot prompting

Showing the model 2-5 examples of input → desired output dramatically improves performance on classification, extraction, and pattern-matching tasks. The model learns the shape of what you want from the examples alone, often better than from instructions.

text
Classify the sentiment of these MPC press-release excerpts as hawkish, dovish, or neutral.
Example 1: "The Committee judges that further tightening will be required to bring inflation sustainably to target."
→ hawkish
Example 2: "The MPC sees scope to reduce the policy rate as inflationary pressures ease."
→ dovish
Now classify:
"The Committee maintained the policy rate at 12.75%, citing balanced risks."

Chain-of-thought

For multi-step reasoning, ask the model to think step by step. The 2022 Wei et al. paper showed that prompting 'Let's think step by step' improves performance on math and logic tasks dramatically. Modern reasoning models (o1, o3, Claude with extended thinking, Gemini Deep Think) build this in.

Structured output

When you need to parse the output programmatically, ask for JSON. Modern APIs (Claude, GPT, Gemini) support 'JSON mode' or structured output schemas that guarantee valid JSON. Schema-guided generation is the production-grade pattern.

What doesn't work

  • Magic words. 'You are the world's best analyst' rarely changes much; concrete instructions do
  • Very long prompts (5000+ tokens) with conflicting constraints — the model gets confused
  • Politeness or rudeness as a tool. Just be specific
  • Asking for 'creativity' without anchoring examples — you get cliché

The iteration discipline

Build a small test set of 10-20 examples of what good and bad output looks like for your task. Iterate on the prompt against that set. This is the difference between prompt engineering (a real practice) and prompt incanting (rumour).

Exercise

You want an LLM to extract key financial metrics from earnings call transcripts. A junior on the team writes: 'You are an expert financial analyst. Please carefully extract the most important financial metrics from the earnings call transcript below. Make sure to be accurate and comprehensive.' Critique the prompt — what is wrong with it, and write a better version that incorporates the practices from this module.

Key takeaways

  • Good prompts are specific, structured, and bounded. Bad prompts are vague and unconstrained
  • Few-shot prompting (showing 2-5 examples) outperforms zero-shot on most analytical tasks
  • Chain-of-thought ('think step by step') significantly improves multi-step reasoning
  • For programmatic use, ask for JSON output and parse with try/catch — modern models support structured output natively
Loading progress…
LeadAfrikPublic Economics Hub