Zum Inhalt springen

Lektion 5 · Prompting Gemini

Examples, Output Formats and Iteration

Use examples to show Gemini the output you want, control format and length, then improve prompts step by step with a small, repeatable test set.

Some wishes are hard to describe but easy to show. "Friendly but not silly" is vague. Two sample replies in that tone are much clearer. This lesson covers examples, formats and iteration, the habit of improving a prompt based on what you see.

Zero-shot and few-shot

  • A zero-shot prompt has instructions only.
  • A few-shot prompt also includes a few worked examples of input and wanted output.

You can start without examples and add them when the output keeps missing a pattern. See also zero-shot and few-shot prompting.

TEXT
Label each message as BILLING, DELIVERY or OTHER. Reply with the label only.

Message: I was charged twice this month.
Label: BILLING

Message: My box has not arrived.
Label: DELIVERY

Message: Do you sell gift cards?
Label: OTHER

Message: The courier left it at the wrong house.
Label:

Good examples are:

  • Consistent. Same layout, same punctuation, same label spelling.
  • Varied. Cover different cases, including a tricky one, so Gemini does not copy surface details.
  • Correct. A mistake in an example is likely to be copied.

If every example has the same length or starts with the same word, expect the answers to do the same. That is useful when you want it and a trap when you do not.

Controlling format and length

Describe the shape you need in plain terms:

TEXT
Return a table with the columns Task, Owner and Due date.
Use "unknown" when the notes do not say.
After the table, add at most two sentences about risks.

Words such as concise are interpreted loosely. A number is clearer: "three bullets, each under 15 words". Models do not count perfectly, so check limits that really matter, such as a character limit in a form.

Python Check a reply against your format rules

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

When a program will read the result, do not rely on wording alone. Use structured output in the API, covered in structured output and multimodal input.

Iterate with intent

The first answer is a draft. Improve it by naming the problem:

Problem Follow-up that helps
Too long "Cut it in half. Keep the dates and the next step."
Too generic "Use my details above. Remove advice that fits anyone."
Wrong tone "Sound calm and factual. No exclamation marks."
Invented fact "I did not say that. Use only the notes I gave."
Ignored a rule Restate the rule and explain why it matters.

If a chat has gone far off course, start fresh with a better first prompt. A pile of corrections can confuse the next answer.

You can also rephrase the request, reorder the parts, or switch to a related task: instead of "Which category is this?", ask "Which of these three options fits best?". These are among the iteration ideas in Google's prompting guide.

Do not force visible reasoning by habit

Recent Gemini models do internal thinking before answering. Google's guide advises against asking them to write out their reasoning as a routine trick. If a task is hard, you can ask the model to think carefully or pick a higher thinking level. When you need to check an answer, ask for evidence instead, for example "name the line in the notes that supports each item".

Test a prompt before you reuse it

A prompt you will use many times deserves a small test set: a few inputs with the answers you expect, including awkward ones. Change one thing, run all cases again and compare. In the stand-in below, plain keyword code plays the role of two prompt versions so you can see the workflow.

Python Stand-in: score two prompt versions on test cases

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

With a real model, answers can vary between runs, so run important cases more than once. More on this in building a prompt test set.

Save what works

Keep a personal prompt library: a document with each prompt, what it is for, one example result and known weaknesses. Mark blanks like [PRODUCT] so you do not send old details by accident.

Read failures before you edit

When a test case fails, do not patch the prompt for that one sentence. Ask what kind of mistake it is:

Failure Likely cause Fix to try
Two labels seem possible The labels overlap Define each label and a tie rule
Extra words around the label The output rule is weak Say "reply with the label only" and show it
Copies wording from an example Examples are too alike Vary length and style
Guesses on empty input No rule for it Add what to reply when there is nothing to label

In the classifier above, the failing message mentions a refund and a missing parcel. A good fix is a clear rule, such as "choose the cause of the problem, not the remedy the customer asks for". A rule like that also helps with messages you have not seen yet. Keep a few fresh cases aside that you do not use while editing. If the prompt only succeeds on the cases you tuned it on, you have learned less than you think.

Common mistake: changing five things at once. If the result improves, you will not know why. Change one thing, then compare.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. When is it especially useful to add examples?

    Examples show patterns that are hard to describe.
  2. 2. Which format request is clearest?

    Concrete numbers leave less to interpretation, though you should still check them.
  3. 3. Why change only one thing between prompt versions?

    Isolating changes makes comparisons meaningful.
  4. 4. What makes a good set of examples?

    Consistency teaches the format, and variety prevents copying accidental details.

Summary

  • Add few-shot examples when instructions alone miss the pattern.
  • State format and length concretely, and check limits that matter.
  • Iterate by naming the problem, and restart when a chat drifts.
  • Test reusable prompts on fixed cases and keep a prompt library.

Next: Instructions, Memory and Skills

Dein Fortschritt wird in diesem Browser gespeichert. Kein Konto nötig.