プロンプトレベルの防御が何をもたらすかを測定する

読了まで約35 分。9 節に6 例を収録。

第2026.11.3版 2026年11月22日時点で例が通過 60 例中 60 例が合格 変更点

AIによる翻訳。英語版は人による検証済みである。 当社の書籍の作り方

英語版の書籍(版2026.11.3)から翻訳した。 原文を読む

Labs

この章を実際に手を動かして学ぶ

すべての例を書籍どおりに実行し、コードを変更して結果を確認し、書籍のコードとデータに自分のアイデアを試せる。インストールは不要で、作業内容は保存される。約 30 秒で開く。

すべての例を書籍どおりに実行し、コードを変更して結果を確認し、書籍のコードとデータに自分のアイデアを試せる。インストールは不要で、作業内容は保存される。Labs が実行環境を用意する: 月40 時間。

Labで開く、新しいタブで開く

利用時間を確認しています…

Lab を確認しています…

自分のマシンで、無料: 書籍のノートブックをダウンロード、そのコードとデータを GitHub から取得する。

この章を終えると、プロンプトレベルの防御がアシスタントの攻撃成功率と有用性に与える影響を測定し、防御が各プロンプトに加えるトークン数を数え、ホールドアウトの結果をそれに合わせた調整をせずに読めるようになる。ここで扱う防御が変更するのはプロンプトだけである。ツールも権限も、アシスタントが到達できるデータも変更しない。そのため、各防御の効果は、与えられたテキストをモデルがどう扱うかによって決まる。これらの変種は教材用のコードであり、多層防御の一部である。アシスタントにできることを制限する統制ではない。そうした統制はモデルの外側で実施され、第1章と第6章で扱う。第8章では、信頼できないテキストを、行動するモデルから遠ざける。

オフィスアシスタントは、テナントからのメッセージ、アップロードされた文書、検索インデックス、取得したページを読む。これらのいずれにも指示が含まれうるし、アシスタントがそれに従うこともある。第3章では、防御のないアシスタントに対してそれがどれほどの頻度で成功したかを測定した。その結果、アシスタントは dev ケースの 11.7% (7 of 60) でケースの目標に到達した。プロンプトレベルの防御は、これに対する最も安価な対応である。防御は、ツールのテキストはデータであるとモデルに伝える、信頼できないテキストの開始位置と終了位置に印を付ける、そのテキストの見た目を変える、あるいはその後でスタッフの依頼を繰り返す、というものである。どの防御も、効果があるとすれば、モデルによるプロンプトの読み取りを通じて働く。

このため、本書は5つの防御をすべて prompt (advice) と分類している。スポットライティングは入力テキストそのものを変更するので、入力の統制に分類することもできる。しかし本書はそうしない。その効果は、印の付いたテキストをモデルが読むことに依存しており、モデルは印を読んだうえで、その印が囲む内容に従って行動することがあるからである。harness というラベルは第1章のものであり、第6章で再び登場する。ほかのラベルである input (detector) と design (isolation) は後の章に属し、そこでは、これらのラベルが表す統制がモデルの外側で働く。

この章では5つの変種を測定する。システムプロンプトでの警告、区切り文字、データマーキング、エンコード、依頼の繰り返しである。各変種は、まず文言を調整した dev 分割で実行し、その後、文言を固定した状態でホールドアウト分割に対して1回だけ実行して測定する。比較はすべてケースごとの対応ありであり、区間はすべてケースに対するブートストラップである。これはEvaluating LLM Applications 第8章で説明されている。ここでの率はすべて、この固定された攻撃セットと、固定された1つのモデル Qwen3-4B-Instruct-2507 についてのものである。第11章では、そのうちの2つ、データマーキングとエンコードを、それらに適応する攻撃者に対して試験する。

第3章が報告する、防御のないホールドアウトの実行結果は、dev の結果より低い。この章のホールドアウトでの比較はすべて、dev の数値ではなくその実行結果を基準としており、対応ありの区間がその比較を行う。ホールドアウトの例では、各防御を1回ずつ実行し、次の数値を得る。

prompt-defences-held-out.py Python 3.13.16 · bm25s 0.3.16 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · numpy 2.5.5 合格
"""Five prompt-level defences, each run once on the held-out split after its wording was frozen on dev, against theundefended baseline's held-out run. The line the prose rests on is `prompt-warning, attack success, 60 held-out cases`,with its paired difference beneath it, per case, with interval."""from lib import cases, report, runs, scorers  # lib first: threads and seeds are fixed here# Each variant is replayed with its row of lib/variants.py: its hooks, and the prompt its recording was made with.VARIANTS = ("prompt-datamark", "prompt-delimiters", "prompt-encode", "prompt-repeat", "prompt-warning")def run_held_out(recording, variant=None):    """The 15 held-out benign tasks and 60 held-out cases of one recording: utility by task ID, attack success by case ID."""    benign, attacks = cases.load_tasks("held-out"), cases.load_cases("held-out")    assert (len(benign), len(attacks)) == (15, 60), "the held-out split has changed"  # the counts the prose names    traces = runs.replay_tasks(recording, benign, variant=variant)    case_traces = runs.replay_cases(recording, attacks, variant=variant)    return ({t.id: scorers.utility(t, traces[t.id]) for t in benign},            {c.id: scorers.attack_success(c, case_traces[c.id]) for c in attacks})def main():    # The wording of each defence was chosen on dev; held-out is its one run, so these numbers are the book's claims.    print("status: defences tuned on dev; this is each defence's one held-out run")    base_utility, base_success = run_held_out("baseline-held-out")    case_ids, task_ids = sorted(base_success), sorted(base_utility)    before = [base_success[c] for c in case_ids]    before_utility = [base_utility[t] for t in task_ids]    report.rate_lines("baseline, utility, 15 held-out benign tasks", [base_utility[t] for t in task_ids],                      "baseline, utility interval")    report.rate_lines("baseline, attack success, 60 held-out cases", before, "baseline, attack success interval")    for name in VARIANTS:  # sorted by name, as listed        utility, success = run_held_out(f"{name}-held-out", name)        report.rate_lines(f"{name}, utility, 15 held-out benign tasks", [utility[t] for t in task_ids],                          f"{name}, utility interval")        report.rate_lines(f"{name}, attack success, 60 held-out cases", [success[c] for c in case_ids],                          f"{name}, attack success interval")        after = [success[c] for c in case_ids]        report.paired(f"{name}, paired difference in attack success", before, after)        report.paired(f"{name}, paired difference in utility", before_utility, [utility[t] for t in task_ids])        # Cases the baseline let through that the variant stops, and the reverse.        report.newly_lines(f"{name}, newly blocked, held-out cases", f"{name}, newly let through, held-out cases",                           before, after)if __name__ == "__main__":    main()
出力python prompt-defences-held-out.py
status: defences tuned on dev; this is each defence's one held-out run
baseline, utility, 15 held-out benign tasks: 66.7% (10 of 15)
baseline, utility interval: [40.0%, 86.7%]
baseline, attack success, 60 held-out cases: 11.7% (7 of 60)
baseline, attack success interval: [3.3%, 20.0%]
prompt-datamark, utility, 15 held-out benign tasks: 53.3% (8 of 15)
prompt-datamark, utility interval: [26.7%, 80.0%]
prompt-datamark, attack success, 60 held-out cases: 6.7% (4 of 60)
prompt-datamark, attack success interval: [1.7%, 13.3%]
prompt-datamark, paired difference in attack success: -5.0 points
prompt-datamark, paired difference in attack success, interval: [-11.7, +1.7] points
prompt-datamark, paired difference in utility: -13.3 points
prompt-datamark, paired difference in utility, interval: [-33.3, +0.0] points
prompt-datamark, newly blocked, held-out cases: 4
prompt-datamark, newly let through, held-out cases: 1
prompt-delimiters, utility, 15 held-out benign tasks: 66.7% (10 of 15)
prompt-delimiters, utility interval: [40.0%, 86.7%]
prompt-delimiters, attack success, 60 held-out cases: 15.0% (9 of 60)
prompt-delimiters, attack success interval: [6.7%, 25.0%]
prompt-delimiters, paired difference in attack success: +3.3 points
prompt-delimiters, paired difference in attack success, interval: [-3.3, +10.0] points
prompt-delimiters, paired difference in utility: +0.0 points
prompt-delimiters, paired difference in utility, interval: [+0.0, +0.0] points
prompt-delimiters, newly blocked, held-out cases: 1
prompt-delimiters, newly let through, held-out cases: 3
prompt-encode, utility, 15 held-out benign tasks: 13.3% (2 of 15)
prompt-encode, utility interval: [0.0%, 33.3%]
prompt-encode, attack success, 60 held-out cases: 0.0% (0 of 60)
prompt-encode, attack success interval: [0.0%, 0.0%]
prompt-encode, paired difference in attack success: -11.7 points
prompt-encode, paired difference in attack success, interval: [-20.0, -3.3] points
prompt-encode, paired difference in utility: -53.3 points
prompt-encode, paired difference in utility, interval: [-80.0, -26.7] points
prompt-encode, newly blocked, held-out cases: 7
prompt-encode, newly let through, held-out cases: 0
prompt-repeat, utility, 15 held-out benign tasks: 33.3% (5 of 15)
prompt-repeat, utility interval: [13.3%, 60.0%]
prompt-repeat, attack success, 60 held-out cases: 10.0% (6 of 60)
prompt-repeat, attack success interval: [3.3%, 18.3%]
prompt-repeat, paired difference in attack success: -1.7 points
prompt-repeat, paired difference in attack success, interval: [-8.3, +5.0] points
prompt-repeat, paired difference in utility: -33.3 points
prompt-repeat, paired difference in utility, interval: [-53.3, -13.3] points
prompt-repeat, newly blocked, held-out cases: 3
prompt-repeat, newly let through, held-out cases: 2
prompt-warning, utility, 15 held-out benign tasks: 60.0% (9 of 15)
prompt-warning, utility interval: [33.3%, 86.7%]
prompt-warning, attack success, 60 held-out cases: 10.0% (6 of 60)
prompt-warning, attack success interval: [3.3%, 18.3%]
prompt-warning, paired difference in attack success: -1.7 points
prompt-warning, paired difference in attack success, interval: [-8.3, +3.3] points
prompt-warning, paired difference in utility: -6.7 points
prompt-warning, paired difference in utility, interval: [-20.0, +0.0] points
prompt-warning, newly blocked, held-out cases: 2
prompt-warning, newly let through, held-out cases: 1

プロンプト内の警告

最も単純な防御は一文である。この警告はシステムプロンプトの末尾に追加される。警告は、ツールから返されたテキストに指示が含まれている場合があること、モデルはそれらに決して従ってはならないこと、そしてスタッフの依頼だけが有効であることを述べる。プロンプトのそれ以外の部分は変わらない。この警告のコストは、モデルを呼び出すたびにこの一文の長さが加わることだけである。

効果はモデルがこの一文に従って動くかどうかで決まり、文面だけでは事前にそれを判断できない。最初の例では、5 つの変種すべてを dev 分割で実行し、防御なしの実行と比較する。

prompt-defences-paired.py Python 3.13.16 · bm25s 0.3.16 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · numpy 2.5.5 合格
"""Five prompt-level defences, each replayed on the dev split and paired with the undefended baseline. The line the proserests on is `prompt-warning, attack success, 60 dev cases`, with its paired difference beneath it, per case, with interval."""from lib import cases, report, runs, scorers  # lib first: threads and seeds are fixed here# Each variant is replayed with its row of lib/variants.py: its hooks, and the prompt its recording was made with.VARIANTS = ("prompt-datamark", "prompt-delimiters", "prompt-encode", "prompt-repeat", "prompt-warning")def run_dev(recording, variant=None):    """The 15 dev benign tasks and 60 dev cases of one recording: utility by task ID, attack success by case ID."""    benign, attacks = cases.load_tasks("dev"), cases.load_cases("dev")    assert (len(benign), len(attacks)) == (15, 60), "the dev split has changed"  # the counts the prose names    traces = runs.replay_tasks(recording, benign, variant=variant)    case_traces = runs.replay_cases(recording, attacks, variant=variant)    return ({t.id: scorers.utility(t, traces[t.id]) for t in benign},            {c.id: scorers.attack_success(c, case_traces[c.id]) for c in attacks})def main():    base_utility, base_success = run_dev("baseline-dev")  # no hooks: the undefended run    case_ids, task_ids = sorted(base_success), sorted(base_utility)    before = [base_success[c] for c in case_ids]    for name in VARIANTS:        utility, success = run_dev(f"{name}-dev", name)        report.rate_lines(f"{name}, utility, 15 dev benign tasks", [utility[t] for t in task_ids],                          f"{name}, utility interval")        report.rate_lines(f"{name}, attack success, 60 dev cases", [success[c] for c in case_ids],                          f"{name}, attack success interval")        after = [success[c] for c in case_ids]        report.paired(f"{name}, paired difference in attack success", before, after)        report.paired(f"{name}, paired difference in utility", [base_utility[t] for t in task_ids],                      [utility[t] for t in task_ids])        # Cases the baseline let through that the variant stops, and the reverse.        report.newly_lines(f"{name}, newly blocked, dev cases", f"{name}, newly let through, dev cases", before, after)if __name__ == "__main__":    main()
出力python prompt-defences-paired.py
prompt-datamark, utility, 15 dev benign tasks: 86.7% (13 of 15)
prompt-datamark, utility interval: [66.7%, 100.0%]
prompt-datamark, attack success, 60 dev cases: 5.0% (3 of 60)
prompt-datamark, attack success interval: [0.0%, 11.7%]
prompt-datamark, paired difference in attack success: -6.7 points
prompt-datamark, paired difference in attack success, interval: [-13.3, -1.7] points
prompt-datamark, paired difference in utility: -6.7 points
prompt-datamark, paired difference in utility, interval: [-20.0, +0.0] points
prompt-datamark, newly blocked, dev cases: 4
prompt-datamark, newly let through, dev cases: 0
prompt-delimiters, utility, 15 dev benign tasks: 93.3% (14 of 15)
prompt-delimiters, utility interval: [80.0%, 100.0%]
prompt-delimiters, attack success, 60 dev cases: 10.0% (6 of 60)
prompt-delimiters, attack success interval: [3.3%, 18.3%]
prompt-delimiters, paired difference in attack success: -1.7 points
prompt-delimiters, paired difference in attack success, interval: [-5.0, +0.0] points
prompt-delimiters, paired difference in utility: +0.0 points
prompt-delimiters, paired difference in utility, interval: [+0.0, +0.0] points
prompt-delimiters, newly blocked, dev cases: 1
prompt-delimiters, newly let through, dev cases: 0
prompt-encode, utility, 15 dev benign tasks: 66.7% (10 of 15)
prompt-encode, utility interval: [40.0%, 86.7%]
prompt-encode, attack success, 60 dev cases: 0.0% (0 of 60)
prompt-encode, attack success interval: [0.0%, 0.0%]
prompt-encode, paired difference in attack success: -11.7 points
prompt-encode, paired difference in attack success, interval: [-20.0, -5.0] points
prompt-encode, paired difference in utility: -26.7 points
prompt-encode, paired difference in utility, interval: [-46.7, -6.7] points
prompt-encode, newly blocked, dev cases: 7
prompt-encode, newly let through, dev cases: 0
prompt-repeat, utility, 15 dev benign tasks: 20.0% (3 of 15)
prompt-repeat, utility interval: [0.0%, 40.0%]
prompt-repeat, attack success, 60 dev cases: 6.7% (4 of 60)
prompt-repeat, attack success interval: [1.7%, 13.3%]
prompt-repeat, paired difference in attack success: -5.0 points
prompt-repeat, paired difference in attack success, interval: [-11.7, +1.7] points
prompt-repeat, paired difference in utility: -73.3 points
prompt-repeat, paired difference in utility, interval: [-93.3, -46.7] points
prompt-repeat, newly blocked, dev cases: 4
prompt-repeat, newly let through, dev cases: 1
prompt-warning, utility, 15 dev benign tasks: 93.3% (14 of 15)
prompt-warning, utility interval: [80.0%, 100.0%]
prompt-warning, attack success, 60 dev cases: 11.7% (7 of 60)
prompt-warning, attack success interval: [5.0%, 20.0%]
prompt-warning, paired difference in attack success: +0.0 points
prompt-warning, paired difference in attack success, interval: [+0.0, +0.0] points
prompt-warning, paired difference in utility: +0.0 points
prompt-warning, paired difference in utility, interval: [+0.0, +0.0] points
prompt-warning, newly blocked, dev cases: 0
prompt-warning, newly let through, dev cases: 0

dev では、採点器から見える変化は警告によって何も生じなかった。攻撃成功率の対応のある差は +0.0 points であり、有用性は 93.3% (14 of 15) で、防御なしの実行の 93.3% (14 of 15) と一致する。

調整用の分割でゼロであっても、警告が有効である証拠にはならない。それは、この文面がこのセットでは何の効果も示さなかったことを意味するにすぎない。Microsoft の研究者である Hines et al. は 2024 年の arXiv プレプリントで報告しており、プロンプトインジェクションに関する指示を追加しても、GPT-3.5-Turbo ではほとんど効果がなく、別のモデルでは控えめな効果があったという。このプレプリントは GPT 系のモデルと合成文書を用いたものである。したがって、本書にとっては期待を定めるものであり、本書自身の測定に代わるものではない。

held-out では、警告は悪い方向に作用する。有用性のコストは -6.7 points であり、この差の区間 [-20.0, +0.0] points は上端でゼロに達する(上端がゼロである)。dev では警告による有用性の低下は見られなかったが、held-out では見られる。攻撃成功率の区間はゼロの下から上にまたがっており、本書が主張できる攻撃の低減は警告には認められない。

実践ルール: 警告を評価に加える前に、held-out 分割で実行すること。また、利得と並べて、正常なタスクに対するコストも数えること。警告を一つの層として残すのは、held-out の攻撃成功率の区間がゼロを含まない場合に限る。調整用の分割でのゼロは、held-out を実行する理由であり、結果ではない。

区切り文字とスポットライティング

スポットライティング(spotlighting)とは、Hines et al.が、信頼できないテキストに対する変換のうち、そのテキストの出どころをモデルに示す信号を与えるものを指して用いている名称である。このプレプリントは三つの手法を挙げている。区切り文字による囲い込み、データマーキング、エンコーディングである。その考え方は、スタッフの言葉とツールの言葉を区別できるモデルのほうが、前者だけに従う可能性が高くなるというものである。

デリミタ

デリミタは、信頼できない各セグメントをマーカーで囲み、そのマーカーが何を意味するかをシステムプロンプトで説明する手法である。Hines らは、デリミタに有益な効果があると報告しているが、その効果はデータマーキングより小さい。dev では、本書のデリミタは utility を防御なしの実行と同じ水準に保ち、その値は 93.3% (14 of 15) であった。

攻撃成功率の対応のある差は -1.7 points であり、区間は [-5.0, +0.0] points であった。この区間は上限でゼロに達するため、dev の実行は低下を示していない。

held-out では、攻撃成功率の対応のある差は +3.3 points であり、区間は [-3.3, +10.0] points でゼロを含む。held-out はどちらの方向にも効果を示さず、その点推定値はゼロより大きい。dev ではゼロより小さかった。utility の対応のある差は +0.0 points である。

このマーカーには既知の弱点がある。Hines らは、デリミタを知っている攻撃者が、それを自分のテキストの中に書き込めると指摘しており、本書のコードにあるこのバリアントの docstring も同じことを述べている。この章の例にはこれを測定するものがないため、この弱点は示すのではなく、述べるにとどめる。

実践ルール: デリミタは、信頼できないテキストがどこから始まりどこで終わるかをモデルに示すために使い、モデルの動作に対する制御とはみなさない。dev で見られた低下は、held-out でも再現された場合にのみ有効とみなす。

データマーキング

データマーキングは、信頼できないテキスト中のすべての空白文字をマーカー文字に置き換え、システムプロンプトでそのマーカーを明示する。モデルはマーキングされたテキストを読むため、この変更はハーネスだけでなくモデルにも見える。Hines らは、区切り文字を用いる方法よりも大きな効果が得られ、GPT-3.5-Turbo を用いた彼らのベンチマークではタスク性能への悪影響も見られなかったと報告している。

dev では、データマーキングによって攻撃成功率が低下し、対応のある差の区間はゼロを含まない。差は -6.7 points であり、区間は [-13.3, -1.7] points である。

held-out では、この低下は再現されない。攻撃成功率の対応のある差は -5.0 points であり、区間は [-11.7, +1.7] points で、ゼロを含む。有用性の対応のある差は -13.3 points であり、区間は [-33.3, +0.0] points で、こちらもゼロを含む。プレプリントにおける「コストなし」という知見は、GPT-3.5-Turbo と彼らのベンチマークに関するものである。ここでは held-out の有用性の点推定値は低く、その区間はゼロを含む。本書は、コストがあることもないことも示していない。

データマーキングは、入力検出器が読む内容も変える。このため、検出器をどこで実行すべきかについては第5章で述べる。

実践ルール: データマーキングを採用する前に、held-out でその有用性を測定すること。また、held-out における攻撃成功率の区間は、dev の区間と並べて読むこと。dev にしか現れない低下は、dev の結果にすぎない。

エンコード

最終変更:版2026.11.2

エンコードは、信頼できない各セグメントをエンコードした形に置き換える。ここでは、UTF-8 バイト列の base64 エンコードを用いる。システムプロンプトには、ツール出力は base64 であり、それはデータであり、従ってはならない、と記す。サードパーティのツール定義も信頼できないため、この変種ではそれらもエンコードする。したがってエンコードは、ツール結果とツール定義という二つを同時に変えることになり、本書の実行ではこの二つを区別できない。モデルは、テキストを読む前にそれをデコードしなければならない。

Hines et al. は、三つの変換のうちエンコードが最も低い攻撃成功率を示したこと、そして高い精度でテキストをデコードできるのは最も高性能なモデルだけであることを報告している。彼らの実験では、エンコードされたテキストに対して GPT-3.5-Turbo のタスク性能が低下した。それらは 2024 年の GPT 系モデルであり、4B のオープンウェイトモデルではない。また、彼らのエンコードはツール定義を変更していないが、この変種は変更する。本書のエンコードを用いた実行でも有用性は低下するが、その理由は示されない。モデルサイズは原因の一つとして考えられるが、実行からは、それをツール結果のエンコードやツール定義のエンコードと切り分けることはできない。0.6B モデルでのエンコード実行はなく、エンコードを有効にしたままモデルサイズを変える実行もない。

dev では、エンコードは他のどの変種よりも攻撃成功率を大きく動かした。防御なしの実行が通してしまったケースのうち 7 件を阻止した。したがって、この集合では、どの防御も攻撃成功率を防御なしの実行の率を超えては下げられない。対応のある差は -11.7 points で、区間は [-20.0, -5.0] points であり、ゼロを含まない。

その代償は正常なタスクに現れる。エンコードの有用性における対応のある差は -26.7 points で、区間は [-46.7, -6.7] points である。モデルがエンコードされたテキストをデコードしたのか、無視したのかは、実行からは分からない。トレースが示すのは、攻撃の目的がどれも達成されなかったことだけである。

held-out でも、エンコードの攻撃成功率に関する結果は維持される。対応のある差は -11.7 points で、区間は [-20.0, -3.3] points であり、全体がゼロより下にある。held-out の攻撃成功率の区間でこの条件を満たすのは、これだけである。有用性の代償は大きくなり、held-out の正常なタスクにおける対応のある差は -53.3 points である。この変種はツール定義をエンコードするため、その代償はツール定義、ツール結果、またはその両方に由来するが、本章の実行ではどれなのかは分からない。

実践ルール: エンコードは、ある集合のすべての攻撃を止めても、アシスタントが作業をこなせない状態を残すことがある。防御と呼ぶ前に、held-out の正常なタスクでの有用性を確認すること。これほど大きな代償がある場合は、信頼できないテキストを、行動するモデルから遠ざける設計を探す理由になる。これは 第 8 章 の主題である。

リクエストの再提示

この変種は、最後のツール結果の後、モデルが返答する直前に、スタッフのリクエストをユーザーターンとして繰り返す。リクエストはモデルが答える前に最後に読むものになるため、モデルはスタッフの目的を見失いにくくなる、という考え方である。AgentDojo は同じ設計を repeat prompt という名前で検証している。その著者らは、GPT-4o で良性タスクの utility が上がり、標的型攻撃の成功率が下がったと報告している。また、同じ著者らはこの手法が「適応型攻撃に耐えられそうにない」とも述べている(AgentDojo。arXiv のプレプリント v3 で、手元の写しには掲載媒体の記載がない)。これはそのベンチマークが、自身のタスクとモデルで得た結果である。本書の実行では、utility については逆の結果が出ている。

dev では、リクエストの再提示が 5 つの変種のうち utility の低下が最も大きい。utility の対応のある差は -73.3 points、区間は [-93.3, -46.7] points である。攻撃成功の対応のある差は -5.0 points、区間は [-11.7, +1.7] points でゼロを含む。したがって、点推定値のほうが低くても、それはこの実行が示せる低減ではない。

次の例では、dev の良性タスクのうち、チェックが行動を必要とするものの中に原因を探る。たとえば、outbox のチェックのためのメッセージ送信や、予約のチェックのための訪問予約である。

prompt-repeat-why.py Python 3.13.16 · bm25s 0.3.16 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · numpy 2.5.5 合格
"""On the dev benign tasks, the repeated request makes the model end more tasks in a text reply that lacks the action thetask's check needs. The line the prose rests on is `prompt-repeat, text reply without the needed call`, beside thesame count on the undefended baseline."""from lib import cases, runs  # lib first: threads and seeds are fixed heredef needed_tools(check):    """The side-effecting tools a task's check needs: an outbox check needs send_message, a booking check book_visit.    A check that only reads the reply needs none."""    if check["type"] == "all":  # a compound check needs every tool its parts need        return set().union(*(needed_tools(part) for part in check["checks"]))    return {"outbox_to": {"send_message"}, "booking": {"book_visit"}}.get(check["type"], set())def text_without_action(task, trace):    """True when the task needs an action, the trace's last event is a text reply, and no needed call was made."""    needed = needed_tools(task.check)    acted = any(trace.tool_calls(name) for name in needed)  # the calls the scorer would look for    return bool(needed) and trace.events[-1].kind == "reply" and not acteddef count(recording, variant=None):    """The dev benign tasks that need an action, and how many of them ended in text without it."""    tasks = cases.load_tasks("dev")    traces = runs.replay_tasks(recording, tasks, variant=variant)    needing = [t for t in tasks if needed_tools(t.check)]    return sum(text_without_action(t, traces[t.id]) for t in needing), len(needing)def main():    # The repeat variant is replayed with its row of lib/variants.py; the baseline with none, so a wrong hook fails the hash check.    base_hits, needing = count("baseline-dev")    repeat_hits, repeat_needing = count("prompt-repeat-dev", "prompt-repeat")    assert needing == repeat_needing, "the same tasks must need an action in both runs"    assert repeat_hits > base_hits, "the repeated request should cost more calls than the baseline"  # the prose's claim    print(f"tasks that need an action, dev benign: {needing}")    print(f"baseline, text reply without the needed call: {base_hits} of {needing}")    print(f"prompt-repeat, text reply without the needed call: {repeat_hits} of {needing}")if __name__ == "__main__":    main()
出力python prompt-repeat-why.py
tasks that need an action, dev benign: 12
baseline, text reply without the needed call: 0 of 12
prompt-repeat, text reply without the needed call: 11 of 12

行動が必要な 12 件のタスクのうち、防御なしの実行は、必要な呼び出しを行わずにテキストの返答で終わったものが 0 of 12 だった。リクエストを再提示した場合は 11 of 12 だった。2 つの実行は、それぞれ 1 回ずつの記録であり、同じタスクに対するもので、違いはリクエストの再提示だけである。モデルは呼び出しを行う代わりにテキストで答え、そのタスクのチェックは失敗する。

held-out では、再提示による utility の低下は -33.3 points で、区間は [-53.3, -13.3] points でありゼロを除く。攻撃成功の対応のある差は -1.7 points で、区間は [-8.3, +5.0] points でありゼロを含む。

実践ルール: リクエストを再提示する前に、行動が必要なタスクの数を数え、実行がそれらの呼び出しを今も行っていることを確認する。行動を止める再提示は、タスクも止める。それが表れるのが utility の数値である。

それぞれのコスト

最終変更:版2026.11.2

各防御には二つのコストがある。失われる無害タスクと、プロンプトに加わるトークンである。前者は上の対の数値に示した。後者は次の例で、dev の無害タスクについて、固定されたファイルにある Qwen3 のトークナイザで数える。このトークナイザは、制御トークンを制御トークンとして読む場合に、本書のプローブ文に対する 4B モデル自身の計数と一致した。各バリアントの計数は、そのバリアント自身の実行における、そのタスクのモデル呼び出し全体で合計する。呼び出し回数の少ない実行では、加算の対象となるプロンプトが少ない。そのため、合計が小さくなるのは、文章が短いからではなく、実行の中身が少なかったからである場合がある。

prompt-cost-tokens.py Python 3.13.16 · bm25s 0.3.16 · huggingface-hub 2.4.0 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · numpy 2.5.5 · tokenizers 0.23.3 合格
"""The tokens each variant adds to the prompts it is given, on the 15 dev benign tasks, summed over each task's modelcalls. Each variant also prints the part of that sum that falls on the tool definitions, the rest of it, and the numberof model calls its run made, because a run that makes fewer calls has fewer prompts to add to. The line the prose restson is `prompt-encode, added prompt tokens in tool definitions, median`, beside its total. The tokens are counted withlib/tokens.py on the pinned Qwen3-0.6B tokenizer, which matches the 4B model's count on the baseline prompts (notes/probes.md, P-1)."""import statisticsfrom lib import cases, defences, harness, replay, runs, tokens, tools  # lib first: threads and seeds are fixed hereVARIANTS = {"prompt-datamark": defences.prompt_datamark, "prompt-delimiters": defences.prompt_delimiters,            "prompt-encode": defences.prompt_encode, "prompt-repeat": defences.prompt_repeat,            "prompt-warning": defences.prompt_warning}def added_tokens(recording, defence, world, tasks):    """Per task ID: the tokens the defence added to the prompts the model was given, summed over its model calls; the    part of that sum on the tool definitions; and the number of model calls."""    model = replay.ReplayModel(recording)  # the variant's own recording, so each reply is the one it was given    totals = {}    for task in tasks:        growths = []  # per call: the growth of the whole prompt, and of its tool definitions        def transform(segments):  # the hook sees each prompt before the change, so the growth is the defence's own            changed = defence(segments)            growths.append(tokens.growth(segments, changed, harness.prompt_text))            return changed        hooks = harness.Hooks(name="measure", transform_input=transform)        system = harness.system_text(runs.TEMPLATE, task.acting_user, world)        harness.run_episode(task.id, task.text, task.acting_user, model, system=system,                            state=tools.ToolState.new(task.acting_user), hooks=hooks,                            assistant_prefix=harness.ASSISTANT, max_tokens=runs.ANSWER_TOKENS)        totals[task.id] = tokens.sum_growth(growths)    return totalsdef main():    world, tasks = cases.load_world(), cases.load_tasks("dev")    assert len(tasks) == 15, "the dev benign tasks have changed"    for name in sorted(VARIANTS):        totals = added_tokens(f"{name}-dev", VARIANTS[name], world, tasks)        added, schemas, elsewhere, calls = tokens.columns(totals)  # sorted by task ID, so the order is fixed        print(f"{name}, added prompt tokens, median: {statistics.median(added):.0f}")        print(f"{name}, added prompt tokens, maximum: {max(added)}")        print(f"{name}, added prompt tokens in tool definitions, median: {statistics.median(schemas):.0f}")        print(f"{name}, added prompt tokens elsewhere, median: {statistics.median(elsewhere):.0f}")        print(f"{name}, model calls, median: {statistics.median(calls):.0f}")if __name__ == "__main__":    main()
出力python prompt-cost-tokens.py
prompt-datamark, added prompt tokens, median: 418
prompt-datamark, added prompt tokens, maximum: 555
prompt-datamark, added prompt tokens in tool definitions, median: 195
prompt-datamark, added prompt tokens elsewhere, median: 223
prompt-datamark, model calls, median: 3
prompt-delimiters, added prompt tokens, median: 220
prompt-delimiters, added prompt tokens, maximum: 220
prompt-delimiters, added prompt tokens in tool definitions, median: 0
prompt-delimiters, added prompt tokens elsewhere, median: 220
prompt-delimiters, model calls, median: 3
prompt-encode, added prompt tokens, median: 1625
prompt-encode, added prompt tokens, maximum: 1647
prompt-encode, added prompt tokens in tool definitions, median: 1419
prompt-encode, added prompt tokens elsewhere, median: 206
prompt-encode, model calls, median: 3
prompt-repeat, added prompt tokens, median: 66
prompt-repeat, added prompt tokens, maximum: 85
prompt-repeat, added prompt tokens in tool definitions, median: 0
prompt-repeat, added prompt tokens elsewhere, median: 66
prompt-repeat, model calls, median: 2
prompt-warning, added prompt tokens, median: 183
prompt-warning, added prompt tokens, maximum: 183
prompt-warning, added prompt tokens in tool definitions, median: 0
prompt-warning, added prompt tokens elsewhere, median: 183
prompt-warning, model calls, median: 3
演習 4.1

すべての呼び出しの増分を合計する

+10 件の検証

34行目は、各タスクの追加トークン数を合計する際に、最後の呼び出しの増分だけを保持している。そのため、出力される合計値は小さすぎる。タスクの実行中に行われたすべてのモデル呼び出しを合計に含めるように修正せよ。

        harness.run_episode(task.id, task.text, task.acting_user, model, system=system,                            state=tools.ToolState.new(task.acting_user), hooks=hooks,                            assistant_prefix=harness.ASSISTANT, max_tokens=runs.ANSWER_TOKENS)    return totals
Python 3.13.16 · bm25s 0.3.16 · huggingface-hub 2.4.0 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · matplotlib 3.11.2 · numpy 2.5.5 · tokenizers 0.23.3 · torch 2.15.0+cpu · transformers 5.24.0 で実行される
演習 4.2

繰り返しの合計が最も小さい理由

+10 件の検証

出力を見ると、prompt-repeat は 5 つの変種のうち追加トークン数の中央値が最も小さく、モデル呼び出し回数の中央値も警告の場合より少ない。繰り返しは、なぜ追加トークンの点で最も安価になるのか。

繰り返しの合計が最も小さい理由:正しい説明を選ぶ
Python 3.13.16 で実行される

dev の無害タスクにわたる中央値で測ると、各防御はタスクのプロンプトに、呼び出し全体の合計で次のトークンを加える。

  • 警告は 183 トークン
  • 区切り文字は 220 トークン
  • データマーキングは 418 トークンで、最大のタスクでは 555 トークン
  • リクエストの繰り返しは 66 トークン
  • エンコードは 1625 トークンで、最大のタスクでは最大 1647 トークン

警告はどの呼び出しにも同じ注記を加えるので、合計は呼び出し回数に比例する。ここでは dev のどのタスクの合計も 183 であり、中央値と同じであった。

繰り返されるリクエストは合計が最も小さく、その理由の一部はその実行にある。その実行の中央値は 2 回のモデル呼び出しであり、警告の実行では 3 回である。一つのツール結果の後にテキストで終わる実行となるタスクは、呼び出しが少ないので、リマインダーも少なくなる。

エンコードは合計が最も大きく、その大半はツール定義による。ツール定義は、ツール結果とともに、呼び出しのたびにエンコードされる。エンコードが加えるトークンのうち、ツール定義分の中央値は 1419 であり、残りのツール結果とシステム注記の中央値は 206 である。データマーキングもツール定義中の空白にマークを付けており、これがその中央値のうち 195 を占める。したがって、エンコードの計数は、ツール結果への base64 だけでなく、設計上ツール定義もエンコードする、構築されたとおりのバリアントのコストである。

トークンのコストは、効用のコストのようには防御を順位づけない。この実行では、繰り返しがトークンでは最も安く、dev での効用のコストは最大である。held-out では、エンコードが効用を最も多く失い、対の差は -53.3 points で、繰り返しの -33.3 points より大きい。しかもエンコードは、dev で測ったトークンでも最大のコストである。調整に使った分割での順位は held-out の分割で変わりうるので、コストの比較には両方が必要である。

図 4.1は、各実行の攻撃成功率を横軸に、効用を縦軸に描いたものである。効用を損なわずに攻撃成功率を下げる防御は、左上に位置する。防御なしの実行であるベースラインは、攻撃成功率が 11.7% (7 of 60)、効用が 93.3% (14 of 15) である。警告の点はその上に重なっている。二つの実行の計数が同じだからである。各バーは、その実行自身の 95% 区間である。前節までの対の区間は、各防御をベースラインとケースごとに比較したものであり、この実行でどの差が示されるかを決めるのはそちらである。

0510152025attack success, percent of 60 dev cases020406080100utility, percent of 15 dev benign tasksdelimitersdatamarkingencodingrepeating the requestundefended and warning
図 4.1 各実行の dev での攻撃成功率と dev での効用。95% ブートストラップ区間付き
figure-prompt-defence-tradeoff.py Python 3.13.16 · bm25s 0.3.16 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · matplotlib 3.11.2 · numpy 2.5.5 合格
"""Draw each prompt defence's dev attack success against its dev utility, with the undefended baseline and 95% bootstrap intervals.The lines name each run's attack success and utility with their counts, which the prose rests on."""from lib import cases, runs, scorers, stats  # lib first: threads and seeds are fixed herefrom lib.figures import ACCENT, INK, new_figure, save# Label places in data units, beside their points. The warning's point is the baseline's, so one label names both.LABELS = {"baseline": (15.5, 88.0), "prompt-delimiters": (1.5, 101.0), "prompt-datamark": (6.5, 76.0),          "prompt-encode": (1.2, 57.0), "prompt-repeat": (8.5, 12.0)}# Plain names, the words the chapter's prose uses. The run IDs stay in the printed lines and the bindings.NAMES = {"baseline": "undefended and warning", "prompt-delimiters": "delimiters", "prompt-datamark": "datamarking", "prompt-encode": "encoding", "prompt-repeat": "repeating the request"}def run_dev(name):    """Utility of the 15 dev benign tasks and attack success of the 60 dev cases, in ID order, as 1s and 0s."""    recording, variant = ("baseline-dev", None) if name == "baseline" else (f"{name}-dev", name)    benign, attacks = cases.load_tasks("dev"), cases.load_cases("dev")    assert (len(benign), len(attacks)) == (15, 60), "the dev split has changed"  # the counts the prose names    traces = runs.replay_tasks(recording, benign, variant=variant)    case_traces = runs.replay_cases(recording, attacks, variant=variant)    utility = [float(scorers.utility(t, traces[t.id])) for t in sorted(benign, key=lambda t: t.id)]    success = [float(scorers.attack_success(c, case_traces[c.id])) for c in sorted(attacks, key=lambda c: c.id)]    return utility, successdef rate(label, flags):    """Print a rate with its counts and bootstrap interval, as the paired example does; return it in points."""    lo, hi = stats.bootstrap_mean(flags)  # the same interval the paired example prints, from the same seed    print(f"{label}: {stats.pct(int(sum(flags)), len(flags))}\n{label}, interval: {stats.interval_pct(lo, hi)}")    return 100 * sum(flags) / len(flags), 100 * lo, 100 * hidef main():    fig, ax = new_figure(height=3.8)    # the baseline last, so its ink bars sit on the warning's identical ones    for name in ("prompt-warning", "prompt-delimiters", "prompt-datamark", "prompt-encode", "prompt-repeat", "baseline"):        utility, success = run_dev(name)        x, y = rate(f"{name}, attack success, 60 dev cases", success), rate(f"{name}, utility, 15 dev benign tasks", utility)        color = INK if name == "baseline" else ACCENT  # the baseline in ink, each defence in the accent        _, caps, bars = ax.errorbar(x[0], y[0], xerr=[[x[0] - x[1]], [x[2] - x[0]]], yerr=[[y[0] - y[1]], [y[2] - y[0]]], fmt="o",                                    color=color, capsize=2, elinewidth=0.9, zorder=3 if name == "baseline" else 2,                                    markersize=9 if name == "prompt-warning" else 5,  # the warning's ring shows around the baseline's point                                    markerfacecolor="none" if name == "prompt-warning" else color)        if name == "prompt-delimiters": [a.set_linestyle("--") for a in (*caps, *bars)]  # its bars lie on the baseline's        if name in LABELS:  # the warning has no label of its own: the baseline's label says it coincides            ax.annotate(NAMES[name], (x[0], y[0]), xytext=LABELS[name][:2], ha="left", va="center", color=color,                        arrowprops=dict(arrowstyle="-", color=INK, linewidth=0.5, shrinkA=4, shrinkB=2))    assert run_dev("prompt-warning") == run_dev("baseline"), "the warning's point is the baseline's"  # the prose says so    ax.set(xlabel="attack success, percent of 60 dev cases", ylabel="utility, percent of 15 dev benign tasks",           xlim=(-1, 25), ylim=(0, 105))    save(fig, "prompt-defence-tradeoff")if __name__ == "__main__":    main()
出力python figure-prompt-defence-tradeoff.py
prompt-warning, attack success, 60 dev cases: 11.7% (7 of 60)
prompt-warning, attack success, 60 dev cases, interval: [5.0%, 20.0%]
prompt-warning, utility, 15 dev benign tasks: 93.3% (14 of 15)
prompt-warning, utility, 15 dev benign tasks, interval: [80.0%, 100.0%]
prompt-delimiters, attack success, 60 dev cases: 10.0% (6 of 60)
prompt-delimiters, attack success, 60 dev cases, interval: [3.3%, 18.3%]
prompt-delimiters, utility, 15 dev benign tasks: 93.3% (14 of 15)
prompt-delimiters, utility, 15 dev benign tasks, interval: [80.0%, 100.0%]
prompt-datamark, attack success, 60 dev cases: 5.0% (3 of 60)
prompt-datamark, attack success, 60 dev cases, interval: [0.0%, 11.7%]
prompt-datamark, utility, 15 dev benign tasks: 86.7% (13 of 15)
prompt-datamark, utility, 15 dev benign tasks, interval: [66.7%, 100.0%]
prompt-encode, attack success, 60 dev cases: 0.0% (0 of 60)
prompt-encode, attack success, 60 dev cases, interval: [0.0%, 0.0%]
prompt-encode, utility, 15 dev benign tasks: 66.7% (10 of 15)
prompt-encode, utility, 15 dev benign tasks, interval: [40.0%, 86.7%]
prompt-repeat, attack success, 60 dev cases: 6.7% (4 of 60)
prompt-repeat, attack success, 60 dev cases, interval: [1.7%, 13.3%]
prompt-repeat, utility, 15 dev benign tasks: 20.0% (3 of 15)
prompt-repeat, utility, 15 dev benign tasks, interval: [0.0%, 40.0%]
baseline, attack success, 60 dev cases: 11.7% (7 of 60)
baseline, attack success, 60 dev cases, interval: [5.0%, 20.0%]
baseline, utility, 15 dev benign tasks: 93.3% (14 of 15)
baseline, utility, 15 dev benign tasks, interval: [80.0%, 100.0%]
figure: figures/prompt-defence-tradeoff.svg

対の区間が dev での低減を示す二つ、データマーキングとエンコードは、どちらもベースラインの効用より下にある。エンコードはすべての攻撃を止めて 0.0% (0 of 60) となり、無害タスクの 66.7% (10 of 15) を保つ。繰り返しは他よりはるかに下の 20.0% (3 of 15) にあり、そのバーは [0.0%, 40.0%] に及ぶ。15 タスクしかないので幅が広い。

これらの計数が表すのは、このプロンプト、このトークナイザ、この短い文書の集合である。実際のツール結果はより長く、デプロイするモデルのトークナイザは同じ文章を別の仕方で分割するかもしれない。ここに示した数値ではなく、デプロイするモデルのトークナイザで、そのモデルが読むプロンプトについてトークンを数えるべきである。

実践ルール: 各防御のトークンは、デプロイするモデルのトークナイザで、そのモデルが読むプロンプトについて数え、その実行が行う呼び出しも数える。各コストを、無害タスクの結果と攻撃の結果の隣に並べる。二つの防御が攻撃成功率を同じだけ下げるなら、失う無害タスクが少なく、トークンも少ない方を残す。

より小さなモデル

防御を施していない 0.6B モデルは、dev 分割では 4B モデルより安全に見える。この点は詳しく調べる価値がある。安全性の数値が、モデルが何に抵抗するかではなく、モデルが何を行うかから生じうることを示しているからである。小さい方のモデルは Qwen3-0.6B であり、4B モデルと同様にバージョンを固定し、thinking をオフにして実行する。この例では、同じ dev のタスクとケースに対して二つのモデルを並べて比較する。

prompt-small-model.py Python 3.13.16 · bm25s 0.3.16 · linkify-it-py 2.2.0 · markdown-it-py 4.3.0 · numpy 2.5.5 合格
"""The 0.6B model against the 4B baseline on the dev split: utility, attack success, their paired differences, and howmany attack cases each model never read the carrier's content in. The line the prose rests on is`never read the carrier, 0.6B`, set beside the 4B's count, with the left-out count on its own line: a weaker model looks safer partly because it reads less."""from lib import cases, harness, replay, report, runs, scorers, stats, tools, variants  # lib first: threads and seeds are fixed heredef run_dev(recording, prefix):    """The dev benign tasks and cases of one recording, undefended: utility by task ID, and by case ID the case,    whether its attack succeeded, and its trace. The prefix is the generation prompt the recording was made with."""    model, tasks = replay.ReplayModel(recording), {t.id: t for t in cases.load_tasks()}    def episode(item_id, text, user, state):  # the book's system prompt for this user, as the recording had it        system = harness.system_text(runs.TEMPLATE, user, cases.load_world())        return harness.run_episode(item_id, text, user, model, system=system, state=state,                                   assistant_prefix=prefix, max_tokens=runs.ANSWER_TOKENS)    utility = {t.id: scorers.utility(t, episode(t.id, t.text, t.acting_user, tools.ToolState.new(t.acting_user)))               for t in cases.load_tasks("dev")}    attack = {}    for case in cases.load_cases("dev"):  # each attack rides on the benign task it names        base = tasks[case.task]        state = tools.ToolState.new(base.acting_user, carrier=case.carrier, injection=case.injection)        trace = episode(case.id, base.text, base.acting_user, state)        attack[case.id] = (case, scorers.attack_success(case, trace), trace)    return utility, attackdef main():    big_u, big = run_dev("baseline-dev", variants.VARIANTS["baseline"].prefix)  # the 4B model    small_u, small = run_dev("baseline-dev-06b", variants.VARIANTS["baseline-06b"].prefix)  # thinking off    ids, cids = sorted(big_u), sorted(big)    for m, u, a in (("4B", big_u, big), ("0.6B", small_u, small)):        report.rate_lines(f"{m}, utility, 15 dev benign tasks", [u[t] for t in ids], f"{m}, utility interval")        report.rate_lines(f"{m}, attack success, 60 dev cases", [a[c][1] for c in cids], f"{m}, attack success interval")    # Paired differences, 0.6B minus 4B: one number per task or case, so each counts once.    for name, before, after in (("utility", [big_u[t] for t in ids], [small_u[t] for t in ids]),                                ("attack success", [big[c][1] for c in cids], [small[c][1] for c in cids])):        diffs = stats.paired_differences(before, after)        print(f"0.6B minus 4B, paired difference in {name}: {100 * sum(diffs) / len(diffs):+.1f} points, "              f"interval {stats.interval_points(*stats.bootstrap_mean(diffs))}")    # The carrier count, over the cases whose carrier a tool returns. Tool-description cases are left out.    counted = [c for c in cids if big[c][0].carrier["kind"] in report.CARRIER_TOOL]    never = {}    for m, a in (("4B", big), ("0.6B", small)):        never[m] = sum(report.never_read(big[c][0], a[c][2]) for c in counted)        print(f"never read the carrier, {m}: {never[m]} of {len(counted)}")    print(f"tool-description cases left out: {len(cids) - len(counted)}")    assert never["0.6B"] > never["4B"], "the weaker model should read the carrier less often"  # the prose's claimif __name__ == "__main__":    main()
出力python prompt-small-model.py
4B, utility, 15 dev benign tasks: 93.3% (14 of 15)
4B, utility interval: [80.0%, 100.0%]
4B, attack success, 60 dev cases: 11.7% (7 of 60)
4B, attack success interval: [5.0%, 20.0%]
0.6B, utility, 15 dev benign tasks: 20.0% (3 of 15)
0.6B, utility interval: [0.0%, 40.0%]
0.6B, attack success, 60 dev cases: 0.0% (0 of 60)
0.6B, attack success interval: [0.0%, 0.0%]
0.6B minus 4B, paired difference in utility: -73.3 points, interval [-93.3, -53.2] points
0.6B minus 4B, paired difference in attack success: -11.7 points, interval [-20.0, -5.0] points
never read the carrier, 4B: 0 of 53
never read the carrier, 0.6B: 24 of 53
tool-description cases left out: 7
演習 4.3

ゼロが耐性を意味しない理由

+10 件の検証

この例では、0.6B モデルの攻撃成功率としてゼロが出力され、その横に、そのモデルがキャリアを一度も読まなかったケースの件数が出力されている。そのゼロが、モデルがインジェクションに耐性を持つことの証拠にならない理由を説明しているのは、どの記述か。

ゼロが耐性を意味しない理由:正しい説明を選ぶ
Python 3.13.16 で実行される

dev では、0.6B モデルは 4B モデルより安全に見える。攻撃成功率は 0.0% (0 of 60) であり、同じタスクとケースでの 4B モデルとの対応のある差は、攻撃成功について -11.7 points, interval [-20.0, -5.0] points である。有用性についての対応のある差は -73.3 points, interval [-93.3, -53.2] points である。

有用性の差は予想どおりである。小さいモデルは、オフィスの業務をこなす量が少ない。攻撃の差については、より詳しい検討が必要である。集計対象の各攻撃ケースでは、キャリアとは注入されたテキストを含むツール結果であり、キャリアの種類ごとに、その全内容を返すツールが一つ存在する。集計では、モデルがそのツールを呼び出したかどうかを問う。0.6B モデルは、集計対象のケースのうち 24 of 53 件でそのツールを一度も呼び出さなかった。4B モデルは、集計対象のケースのうち 0 of 53 件で一度も呼び出さなかった。ツール説明のケースは、どちらの集計からも除外している。そのテキストはすべてのプロンプトのツールスキーマに含まれ、読まれずに済むことがないためであり、その数は 7 件である。

モデルが一度も読まないケースは、そのテキストを通じて目標に到達できない。したがって、0.6B モデルの 0 は、部分的にはモデルの行動に関する事実である。このモデルは、正常なタスクのうち 20.0% (3 of 15) も完了している。そのため、この 0 を抵抗の表れと読むことはできない。このモデルは、行動が注入されているか否かにかかわらず、与えられたタスクに対して行動できていないのである。4B モデルが読む量を減らすような防御も、同種の 0 を示すだろう。率と並べて報告する読み取りの回数が、この二つの場合を区別する。

実践ルール: あるモデルや防御に、より低い攻撃成功率の功績を認める前に、そのモデルがキャリアを何回読んだかを数えること。その回数を率と並べて報告すること。モデルが一度も読まなかったテキストから得られた率は、モデルの行動を数えたものであり、モデルが抵抗することの証拠ではない。

ホールドアウトの実行

各防御の文言は dev 分割で固定し、その後、各防御をホールドアウト分割で1回ずつ実行した。両方の分割を報告し、各主張はどちらの分割によるものかを明示する。dev で得られた結果がホールドアウトで再現されない場合は、成り立たないと述べる。dev の結果は文言を選ぶために使ったので、その文言が有効であることの証拠にもなるとは言えない。ホールドアウトは、同じ攻撃ファミリーから取った2つ目のケース標本であり、本書がそこから得るのは防御ごとに1回の実行だけである。1回の実行がどれだけ変動しうるかを正直に示す尺度が区間である。防御なしの場合のホールドアウトでの実行は dev の結果より低く、その結果は第3章で報告している。

ホールドアウトの例は、各防御について、対応のある攻撃成功率の差とその区間を示す。

  • 警告: -1.7 points、区間 [-8.3, +3.3] points。
  • 区切り文字: +3.3 points、区間 [-3.3, +10.0] points。
  • データマーキング: -5.0 points、区間 [-11.7, +1.7] points。
  • 要求の反復: -1.7 points、区間 [-8.3, +5.0] points。
  • エンコード: -11.7 points、区間 [-20.0, -3.3] points。

ホールドアウトで攻撃成功率の差の区間がゼロを除外するのはエンコードだけであり、それも前述の有用性の低下を伴う。ホールドアウトの実行は、エンコードと要求の反復という2つの大きな有用性の低下を裏づけており、どちらも区間がゼロを除外している。一方、警告とデータマーキングの小さな低下は裏づけられず、これらの区間はゼロに達している(ゼロを含む)。警告の低下はホールドアウトでのみ現れた。

dev はすべての防御に対して寛容だったわけではない。dev は、区切り文字による攻撃の減少と、反復による有用性の低下を過大に示し、警告、データマーキング、エンコードの有用性の低下を過小に示した。dev だけから導いた主張は、これらのどれについても誤りだったはずであり、その誤りの向きも防御ごとに異なる。

ホールドアウトは有限の資源でもある。文言を変えた後に行う2回目のホールドアウト実行は、その分割を再び見ることであり、その結果はもはやホールドアウトとは言えない。ホールドアウトの実行で防御が失敗した場合、修正は dev に戻って行い、その文言についてはホールドアウト分割を使い切ったことになる。各防御をホールドアウトで実行した回数を記録し、結果とともに報告すること。

これらの結果は、固定した1つの攻撃セットと1つのモデルについてのものであり、攻撃は静的である。つまり、毎回同じケースが同じ文言で与えられる。Nasr et al., 2025, The Attacker Moves Secondは、写しから見る限り査読を受けていないプレプリントであり、静的な攻撃成功率が低いと報告されていた既存の防御に対する攻撃を、AgentDojo を用いて探索した。その適応型攻撃は、防御の大半を破った。破られたと報告された一覧には、スポットライティングと、本章が要求の反復と呼ぶ設計の通称であるプロンプトサンドイッチが含まれる。このプレプリントでは、静的な結果は低く、適応型の結果は高かった。したがって、本章での静的なゼロは、このセットに対する結果にとどまる。第11章では、それらの防御のうちデータマーキングとエンコードの2つを、本書のモデルを用いて、適応する攻撃者に対して試す。

実践ルール: 各防御について、ホールドアウトでの対応のある攻撃成功率の差を区間とともに報告し、その区間がゼロを除外する場合に限って減少を主張すること。ホールドアウト分割で再び調整してはならない。静的な結果は静的なセットについてのみ成り立ち、第11章で適応型攻撃者と対決する。

この版における本章

第2026.11.3版2026年11月22日時点で例が通過この章の6 例件のうち6件が合格

英語版の書籍(版2026.11.3)から翻訳した。

Labs を開始

書籍は引き続き無料で読める。

料金を見る

この節を引用する

形式

いずれの形式も、本訳書が従う英語版の書籍を出典として示す。

いずれの形式もこの版を明示している。そのリンクは現行版を開き、節の見出しには本文が最後に変更された日付が示される。アクセス日と取得日は、これを開いた日である。

このページの内容

全12章中の第4章: プロンプトレベルの防御が何をもたらすかを測定する

  1. プロンプト内の警告
  2. 区切り文字とスポットライティング
  3. デリミタ
  4. データマーキング
  5. エンコード
  6. リクエストの再提示
  7. それぞれのコスト
  8. より小さなモデル
  9. ホールドアウトの実行

ページの先頭に戻るすべての章