Prompt engineering, tested: six tricks, 411 answers, scored by code

LLM Mart · Nov 6, 2026 · 6 views 7.5k listing impressions
Prompt engineering, tested: six tricks, 411 answers, scored by code

Watch the video: Prompt Engineering, Tested. This article is the long version: every prompt we used, every number, and a script to run the same tests yourself.

TL;DR

  • Write the rules down. A vague "write a slugify function" passed about 7 of our 10 unit tests; the same request with the rules spelled out passed 8 to 10, depending on the model.
  • Tell it and show it. "Use our house style" scored zero on all three models: it can't know your style. Rules alone or three examples alone scored 7 to 10 out of 10; both together scored 19 of 20 on the smallest model and 10 of 10 on the others.
  • If a program reads the answer, write the shape down. "As JSON" produced zero usable answers out of 19, every one wrapped in a markdown code fence. An exact shape produced 19 of 19.
  • "You are a world-class senior engineer" did nothing. Same score with and without it, on all three models.
  • "Think step by step" helped the small local models (14 to 19 correct out of 20, and 7 to 9 out of 10) and made no difference to Gemini, which got all 10 right either way.
  • Context needs instructions, and checking. Shown our database helper, the two bigger models used it every time. The smallest copied it into its own file 9 times out of 10, and still only imported it once in 10 after we told it to.
  • The method matters more than any trick: same task, one change, many runs, scored by code. A script at the end runs three of these tests on your own machine.

Most of us have a folder of prompt tips. "Be specific." "Give examples." "Tell it it's an expert." "Ask it to think step by step." They sound right, and they get passed around because they sound right. Almost nobody checks them.

So we did. This is lesson one of llmmart's AI-assisted development course, and the lesson is less any single trick than the way we found out which ones work.

How we tested

Every technique got two prompts (or four, for one of them): a plain one, and the same request with the technique added. Nothing else changed. Then we asked each prompt again and again and scored every answer with code.

The models. Three of them, picked so the results aren't one model's quirk:

Model Where it ran Runs per single-task prompt
Gemma 4 (gemma4:latest) on a Mac, through Ollama 10
gpt-oss 20B (gpt-oss:20b) on a Mac, through Ollama 5
Gemini (Flash models) Google's free tier 4

Two experiments use a set of items instead of one task (ten pull requests, ten date questions); there each item is asked once or twice per model. All prompts used each model's default settings. In total: 411 answers, run on 5 and 6 November 2026.

The scoring. No model graded another model. Each answer passes or fails a check written in plain Python: unit tests for a function, json.loads and a key check for JSON, an exact date for a date question. Here is the whole idea in a few lines:

def score(answer: str) -> bool:
    try:
        obj = json.loads(answer)        # a program will read this, so it must parse
    except json.JSONDecodeError:
        return False
    return sorted(obj) == ["app_version", "platform", "reporter", "severity", "summary"]

passes = sum(score(ask(prompt)) for _ in range(10))
print(f"{passes} of 10")

That's an eval: a test for a prompt. If you take one thing from this article, take that.

One honest caveat up front. Some of the plain prompts fail tests they couldn't have known about. The vague slugify request never heard our rules; the prompt without our database helper couldn't have used it. That is the point of those two experiments, not a flaw in them: a model can't follow a spec you didn't write. Sample sizes are small, so we only read big differences as real.

1. Write the rules down

The task: a Python function slugify(title) that turns a title into the end of a URL, checked by ten unit tests: accents become plain letters ("Crème brûlée & café" gives "creme-brulee-cafe"), apostrophes vanish without a gap ("C'est" gives "cest"), runs of punctuation become one hyphen, "ß" becomes "ss", empty input gives "", and the result is at most 60 characters, cut at a hyphen.

Plain prompt:

Write a Python function slugify(title) that turns a title into a URL slug. Reply with the code in one python code block.

With the rules: the same request plus the six rules above as a bulleted list, two examples, and "use only the standard library".

Results (average tests passed, out of 10):

Model Vague Rules written down
Gemma 4 6.7 8.0
gpt-oss 20B 7.0 9.6
Gemini Flash 7.8 10.0

Every model wrote a reasonable slugify from the vague prompt. What it couldn't do was guess our slugify: whether apostrophes leave a gap, whether there's a length limit, what happens to ß. Those are the decisions in your head, and the prompt is the only way in.

One detail: one vague answer imported unidecode, a third-party package. Our test folder provides a stand-in for it, so it was judged on what its code did, not on what was installed.

2. Tell it and show it

The task: a changelog line for a pull request, in our house style: Fixed: login loop on safari (#305). One of four words (Added, Fixed, Changed, Removed), a colon, a lowercase past-tense description with no full stop, the PR number in brackets, at most 72 characters, nothing else. Ten pull requests, each asked twice on Gemma 4 and once on the others.

Four prompts:

  1. Named: "Use our house style." plus the request.
  2. Rules: the style described as four bullet points.
  3. Examples: no rules, three example lines instead.
  4. Both: the rules, then the examples.

Results (lines that matched the style exactly):

Model Named Rules Examples Both
Gemma 4 0 of 20 15 of 20 15 of 20 19 of 20
gpt-oss 20B 0 of 10 7 of 10 9 of 10 10 of 10
Gemini Flash 0 of 10 10 of 10 10 of 10 10 of 10

Naming a convention the model has never seen gets you its own convention, every time. Rules and examples each got most of the way; neither won cleanly on its own. Together they were the best on every model. The rules say what matters; the examples show what it looks like, including the things that are hard to state ("lowercase, even for Safari").

3. If a program reads it, write the shape down

The task: pull the details out of a short bug report: who reported it, the platform, the app version, a severity, a one-line summary.

Plain prompt: "Extract the key details of this bug report as JSON." plus the report.

With a contract:

Return only one JSON object, no prose and no code fence, with exactly these keys: {"reporter": string, "platform": "ios" | "android" | "web", "app_version": string, "severity": "low" | "medium" | "high", "summary": string}

The check is what your code would do: parse the whole answer with json.loads, then check the keys and three of the values.

Results:

Model "As JSON" Contract
Gemma 4 0 of 10 10 of 10
gpt-oss 20B 0 of 5 5 of 5
Gemini Flash 0 of 4 4 of 4

All 19 "as JSON" answers came back inside a markdown code fence (```json), which json.loads rejects. Strip the fence and they parse, but that isn't the end of it: Gemma's ten answers used six different sets of keys (bug_report, bug_details, report_details, nested in different ways). Code that reads one of those breaks on the next.

The contract fixed both, on every run. In production, validate anyway and retry on a failure: a contract makes bad output rare, not impossible. Many APIs also offer a structured-output or JSON mode that enforces a schema; that's the same idea, done by the API.

4. "You are a world-class senior engineer"

The task: the slugify function from experiment 1, with the rules written down. The only change is one sentence in front:

You are a world-class senior software engineer with 20 years of experience writing flawless, production-grade Python.

Results (average tests passed, out of 10):

Model Rules only Role + rules
Gemma 4 7.3 6.7
gpt-oss 20B 9.6 9.4
Gemini Flash 10.0 10.0

No improvement on any model. The small drops are within run-to-run noise at these sample sizes, so the honest reading is "no effect", not "it hurts". (Gemma's rules-only score here, 7.3, differs from experiment 1's 8.0 because these are separate runs of the same prompt: that gap is the noise.)

Role prompts can change tone and focus, and a role that carries real information ("you are reviewing for a payments team, so flag anything that touches money") is a different thing: that's context. But flattery that adds no information didn't add a single passing test. Spend the words on the task instead.

5. "Think step by step"

The task: ten date questions. "A task starts on 2026-01-30. It takes 15 working days (Monday to Friday, no holidays), counted from the next working day after the start. On what date is it finished?" The answer is checked against a date computed in code.

Plain: "Give only the date, as YYYY-MM-DD." Steps: "Work it out step by step, then put the final answer alone on the last line as YYYY-MM-DD."

Results (correct dates):

Model Date only Step by step
Gemma 4 14 of 20 19 of 20
gpt-oss 20B 7 of 10 9 of 10
Gemini Flash 10 of 10 10 of 10

On the two local models, asking for the working helped a lot: weekends are easy to miscount in your head, and writing the days out catches it. Gemini got every one right either way. Current hosted models increasingly reason before answering without being asked, so the trick matters less there. If you run small models locally, keep the line; with a big hosted model, test before you assume it helps.

6. Context, and checking it was used

The task: "write a Python function save_user(email, name) that stores a new user in the users table and returns the new id; if the email is taken, return None." Our project already has a helper for exactly that:

# db.py (our project)
def insert_one(table: str, row: dict) -> int:
    """Insert one row and return its new id. Raises db.Conflict if a unique key clashes."""

class Conflict(Exception): ...

The test replaces db with a fake that records every call, then checks that save_user stored the row through our helper and returned None for a taken email.

Three prompts: no mention of the helper; the helper pasted in ("use our database module, shown here"); and the helper plus one sentence: "It is already in db.py: import it, don't rewrite it."

Results (answers that used our helper correctly):

Model Not mentioned Shown Shown + "import it"
Gemma 4 0 of 10 0 of 10 1 of 10
gpt-oss 20B 0 of 5 5 of 5 5 of 5
Gemini Flash 0 of 4 4 of 4 4 of 4

Without the helper, every model invented its own database code: sqlite3 in 9 of the 19 answers, Postgres through psycopg2 in 3, SQLAlchemy once, and an in-memory store in the rest. None of them could have used ours. Shown the helper, the two bigger models imported it every time.

Gemma 4 did something else. In 9 of its 10 answers it copied our helper's signature into its own file and wrote a fake body for it, then used the copy; the tenth called our helper without importing it. Adding "import it, don't rewrite it" got one correct import out of ten. Seven answers copied it again, and two used it without importing it.

So context is two things: showing the model your code, and saying how it fits ("it's in db.py, import it"). And with a small model, check what it wrote before it touches your project. A test like ours, with a fake db that records calls, is a cheap way to do that.

What we didn't test

  • Three models, one task per technique. Other models, versions and tasks will give other numbers. Treat these as a demonstration of the method and a strong hint, not a law.
  • Small samples. 4 to 20 answers per prompt per model. We only claim differences that are large compared with the run-to-run noise (see experiment 4).
  • Default settings. No temperature tuning, no system prompts, no structured-output modes.
  • Cost and speed. "Step by step" answers are much longer, so they cost more tokens and take longer. We didn't measure that here.

Check yourself

  1. Why did "use our house style" score zero on every model, while three examples scored 7 to 10?
  2. All 19 "as JSON" answers parsed once the code fence was removed. Why is that still a failure?
  3. Gemma's "rules only" slugify scored 8.0 in one experiment and 7.3 in another, with the same prompt. What does that tell you about reading a one-run comparison?
  4. When would a role prompt carry real information, and how is that different from "world-class senior engineer"?
  5. You switch from a small local model to a big hosted one. Which of these six results would you re-test first, and why?
Answers
  1. The model has never seen our house style; naming it gives no information. Examples carry the format directly.
  2. A program reads the answer. Code that calls json.loads on it fails, and even after stripping the fence the keys changed from answer to answer.
  3. The same prompt varies run to run. A single before-and-after can show a "difference" that is only noise: run each prompt many times.
  4. When it tells the model something about the job (the audience, the risk, what to look for). A title with no information didn't change the score.
  5. "Think step by step" and the context result: both depended on the model in our tests.

Common mistakes

  • Judging a prompt by one good answer. Run it ten times and count.
  • Asking for "JSON" and parsing whatever comes back. Write the exact shape, and validate.
  • Naming a convention instead of showing it. "Our style" means nothing to the model; rules and an example do.
  • Pasting code and assuming it'll be used. Say where it lives and how to use it, then check.
  • Keeping rituals that never moved a score. If a line doesn't change the result, it's just tokens.

Run three of these tests yourself

code/prompt_lab.py runs experiments 2, 3 and 5 (the house style, the contract and the dates) against any model you have in Ollama. It uses only Python's standard library.

ollama pull gemma4
python3 prompt_lab.py gemma4 5

It prints a tally for each prompt. This is a short run on Gemma 4 (python3 prompt_lab.py gemma4:latest 2, 6 November 2026); yours will differ:

model gemma4:latest, 2 runs where a task is asked repeatedly

1. Output contract: 'as JSON' against an exact shape
  as JSON          0 of 2
  contract         2 of 2

2. House style: named, described, shown, or both (4 pull requests)
  named            0 of 4
  rules            2 of 4
  examples         3 of 4
  both             4 of 4

3. Working days: the date only, or step by step (5 questions)
  date only        3 of 5
  step by step     3 of 5

Notice the last two lines: in this run, step by step made no difference. Five questions is too few to tell. The lab asked twenty and got 14 against 19. Raise the runs before you believe a result, including ours.

Then make it yours: replace one task with a prompt you use every day, write a score function for three things a good answer always has, run it ten times, change one thing in the prompt, and run it again. That's the whole course in one exercise.


Method and every raw answer: the lab behind this article ran 411 answers on 5 and 6 November 2026. Counts are exact; averages are rounded to one decimal place.

0 0 0 0 Sign in to react

Comments (0)

Sign in to join the conversation.

No comments yet.