Garakgarak 0.17.0 Ā· Python 3.10+
0%
1
Curious builder0 XP earned Ā· 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
23 small wins to finish your pathNext lesson →

What a target must return

One function, two rules, and a handful of ways to get it wrong. This lesson is the contract, because every strange scan later starts here.

The signature

python
def reply(prompt, **kwargs):
    return ["one answer"]

The prompt arrives first and as a string. **kwargs catches everything else garak passes, and a function without it fails the moment garak sends a setting it did not expect.

The return

A list, and one entry per answer. Returning a bare string is the commonest mistake, and garak treats the string as the sequence it asked for, so every character becomes an answer.

Example
cat > wrong_bot.py <<'PY'
def reply(prompt, **kwargs):
    return "a string, not a list"
PY
garak -t function -n wrong_bot#reply --spec probes.test.Blank --generations 1 --report_prefix wrong 2>&1 | tail -4

Twenty characters became twenty answers, and garak says so: it asked for one response and got twenty. The message names the count rather than the cause, so the first time you see it, look at what your function returns.

Returning nothing

A generator may return [None] when it has no answer, for a refusal or a filtered response. There is then nothing for a detector to score.

Example
cat > none_bot.py <<'PY'
def reply(prompt, **kwargs):
    return [None]
PY
garak -t function -n none_bot#reply --spec probes.test.Blank --generations 1 --report_prefix none 2>&1 | tail -4

The verdict is SKIP, and the count is nothing out of nothing. A target that answers nothing is not a target that passed, and garak keeps the two apart rather than flattering the score.

Every rule here is about the list. One prompt can produce several answers, detectors score each one, and the rate at the end is over answers rather than prompts. Getting the shape wrong changes every number in the report.
Try it yourself
  • Return [None] and look for the nones column in the verdict.
  • Return two strings from one call and watch the totals double.
  • Remove **kwargs and run a probe that passes a setting.

Little by little, you're building something great.