1 / 19
1
ComplianceGPT Lab · AI Innovation & Diffusion REU 2026

Week 3 — Prompt Engineering

Can you fix a wrong prediction just by changing the prompt? No new code, no new model.

Monday Jul 7
Prompting strategies + notebook
Wednesday Jul 9
Project proposal presentations
Friday Jul 10
The extraction task in depth

No new theory today. You already know how the model works inside (Week 2). This week is 100% practical: three prompting strategies, one real failing case, and your own Ollama instance running the exact model (gemma3:4b) from the real 94.2% experiment.

2

Where We Left Off

129 / 137
correct — 94.2%
8
real failures — 3 FP, 5 FN

Every one of those 8 errors happened with the same code, same model, same weights. The only thing that changes today is the prompt.

This week's question

"If I write a smarter prompt — more examples, more structure, more reasoning steps — does the answer change? And if it does, why didn't the production system already do that?"

3
Prompting Strategies

Zero-Shot

Give the model only the instructions and the schema. No worked examples. Fastest to write.

Extract from this scenario: {scenario} Return JSON with: sender_role, receiver_role, purpose, phi_involved

Works well when

The task is close to something the model has seen constantly in training — simple, familiar formats.

Fails on

Novel schemas, edge cases, or anything requiring the model to not follow its strongest prior (e.g. "mentions a lawsuit" ≠ "has a court order").

4
Prompting Strategies

Few-Shot

Show 2–5 worked (scenario → correct JSON) examples before the real question. The model pattern-matches against your examples, not just its training data.

Example 1: Scenario: ... JSON: {...} Example 2: Scenario: ... JSON: {...} Now extract: {scenario}

The one rule that matters: your examples must cover the edge case you actually care about. A few-shot prompt with two easy examples won't teach the model to handle a hard one — it has to see something shaped like the failure you're trying to fix.

5
Prompting Strategies

Chain-of-Thought

Ask the model to reason step-by-step before committing to an answer. More tokens, more time — but it can catch ungrounded inferences a one-shot answer would miss.

Think step by step: 1. Who is the sender? 2. What is the purpose? 3. Is PHI involved? Then output JSON.

The real payoff isn't the reasoning text itself — it's forcing the model to justify each field individually instead of pattern-matching the whole scenario in one leap. "Is there explicit evidence of X?" is a different, harder question than "does this scenario feel like X?"

6
Live Demo

All Three, on One Real Case verified

Case row_id 40 — real false positive, ground truth DENIED. Ran all three prompts today against gemma3:4b on a simplified 6-field schema.

StrategyField that misfiredSimplified verdictCorrect?
Zero-shotis_required_by_law = truePERMITTED
Few-shot (2 examples)is_required_by_law = truePERMITTED
Chain-of-thoughtis_business_associate = truePERMITTED

None of the three naive strategies fixed it. Chain-of-thought didn't repeat the exact same mistake — it made a different one. That's the honest result you'll get in the notebook too. Hold that thought for slide 8.

7

Why Extraction Is Hard

Not model laziness — these are genuinely ambiguous even for a careful human reader.

8

Prompt Engineering Levers

Levers you have

  • Temperature — lower = more consistent, higher = more creative (never above 0 for extraction)
  • System prompt — instructions given before the scenario, framed as identity/role
  • Output format constraints — JSON schema, strict mode, marker tokens
  • Negative examples — "do NOT set X to true unless the text says Y explicitly"
  • Reasoning traces — ask the model to explain its choice before the final answer

What you're really doing

Every lever above is a way of narrowing the space of plausible-sounding-but-wrong answers. None of them add new knowledge to the model — they only change which of its existing patterns gets activated by your specific wording.

9

Temperature — Why It's Always 0 for Extraction

Try this yourself in Exercise 5 of today's notebook: run the identical zero-shot prompt 3 times at temperature=0, and 3 times at temperature=0.9.

temperature = 0

Always picks the single highest-probability next token. Deterministic — same input, same output, every run. This is what reproducible research requires.

temperature = 0.9

Samples from the probability distribution. Same scenario can flip between PERMITTED and DENIED on different runs — your accuracy number stops meaning anything.

If your extraction pipeline doesn't set temperature=0 explicitly, you don't have one accuracy number — you have a different one every time you run it.

10

The Real Prompt Is Not 150 Tokens

Today's notebook uses a 6-field toy schema. The production system (connector/llm1_extractor.py) uses 40 fields and roughly 2,000 lines of instructions.

Your toy schema today

6 fields, one line of description each. Enough to learn zero-shot vs few-shot vs CoT — not enough to actually beat the real system.

The real production prompt

40 fields, 14 numbered rules, explicit trigger words per oracle, worked edge cases, and instructions like "a lawsuit filing, subpoena, or legal dispute alone ≠ court order" — added specifically because a real case broke the simpler version.

Every one of those 2,000 lines exists because someone ran the exact exercise you just ran, found a hallucination, and wrote one more instruction to stop it. That is quite literally what prompt engineering research looks like at scale.

11

Live Coding — Reading the Real Rules

Friday, July 10: open connector/llm1_extractor.py, lines 87–270, together.

Rule #11 — the one that fixes Exercise 1's exact failure

"…CRITICAL: 'lawsuit', 'legal dispute', 'legal battle', 'malpractice case'… → instrument_type='none' → DENIED unless you separately find one of the specific instrument keywords above."

This is exactly the failure mode from case 40 — a legal/billing-sounding context with no actual court order — encoded as an explicit negative rule instead of hoped-for good judgment.

We'll match 3–4 more numbered rules to the failure modes on slide 7. Bring your Exercise 1–4 results — you'll recognize your own hallucination in there.

12

Today's Notebook — week3_prompting.ipynb

What's given to you

  • A working call_ollama() function
  • The real case 40 scenario text + ground truth
  • Exercise 1 (zero-shot) fully worked, as a model to follow

What you write

  • Ex 2 — your own 2 few-shot examples
  • Ex 3 — your own chain-of-thought steps
  • Ex 4 — comparison table across all three
  • Ex 5 — temperature=0 vs 0.9 (bonus)
  • Ex 6 — repeat everything on your own Week 2 wrong prediction

Runs entirely on your laptop — gemma3:4b via local Ollama, no cluster, no API key. If Ollama isn't running: open the Ollama app, or run ollama serve in a terminal.

13
Wednesday, July 9

Project Proposal Presentations

5 minutes each, informal, slides optional. Goal: get early feedback before you commit to a direction for the rest of the summer.

Structure (5 min)

  1. Problem (1 min) — what question, and why is it interesting?
  2. Method (2 min) — what experiments, what variables, what you'll measure
  3. Expected result (1 min) — your hypothesis
  4. Scope (1 min) — what's realistic in 3 weeks? Your Week 5 deliverable?

Feedback norms

2 minutes of questions after each proposal. We ask: "is this feasible in 3 weeks?" and "what's the one most important thing to nail?" Direct, not harsh. The goal is to help, not to impress.

14

Six Project Options

Choose one, or propose your own with approval. Full descriptions on the Student Projects page.

LLM Benchmark Comparison

Gemma3 vs Llama vs Qwen on the same 137-row benchmark. Model-specific vs universal failure modes?

Adversarial Scenarios

Write 30 edge cases that sound like violations but are permitted (or vice versa). Analyze failure patterns.

Prompt Engineering Study

Systematically test 5 strategies (today's 3 plus system prompts and schema constraints) on 30 scenarios.

Explanation Quality Study

Are ComplianceGPT's generated explanations correct, faithful, and useful? Build a rubric, rate 50 of them.

GDPR Generalization Study

Does a prompting strategy that helps HIPAA also help GDPR? Run the same 5 prompts on both.

Error Taxonomy

Categorize wrong predictions from 3 models into a taxonomy. Does the category predict which prompt fixes it?

15

Week 3 Deliverable

1. Oral proposal — Wednesday, July 9 (in class)

5-minute pitch: problem, research question (1 sentence), method, how you'll know if it worked.

2. Written proposal (1 page) — Friday, July 11

Graded on specificity. "I will run experiments" is not a milestone.

16

Recommended Reading

Brown et al. — "Language Models are Few-Shot Learners" (GPT-3, 2020)

Read the abstract and Section 2 — the original definition of few-shot learning, from the paper that made it a standard technique.

Wei et al. — "Chain-of-Thought Prompting Elicits Reasoning in LLMs" (2022)

Short paper. Read the introduction and Figure 1 — the original chain-of-thought result on grade-school math word problems.

17

This Week at a Glance

DayFocusDeliverable
Mon Jul 7Zero/few-shot/CoT + week3_prompting.ipynbNotebook, flexible timing
Wed Jul 9Project proposal presentations (on campus)5-min oral pitch
Fri Jul 10Why extraction is hard + live code read of the real prompt
Fri Jul 111-page written proposal due
18

Recap: What Changed and What Didn't

Same as Week 2

Same model (gemma3:4b), same weights, same tokenizer, same attention mechanism. Nothing about the network changed.

New this week

Only the text you send it. And that alone was enough to change the answer on case 40 — three different ways, none of them fully correct.

The takeaway: prompting is real engineering, with real trade-offs and real failure modes — not guessing at magic words. That's what today's exercises, and Friday's read of the real 2,000-line prompt, are meant to prove to you directly.

19

Before Monday

Check your setup

  • Ollama installed and running (ollama serve)
  • gemma3:4b pulled (ollama pull gemma3:4b)
  • Your Week 2 cluster results CSV on hand for Exercise 6

Start thinking about your project

Proposal presentations are Wednesday. Look back at your Week 2 project selection message and the six options on slide 14 — come Monday with a rough direction so today's exercises can double as pilot evidence for your proposal.