Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx agentmods add instructions/danyuchn/pii-guard/agents-mdgit clone --depth 1 https://github.com/danyuchn/pii-guardWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/instructions/danyuchn/pii-guard/agents-md)<a href="https://agentmods.dev/instructions/danyuchn/pii-guard/agents-md"><img src="https://agentmods.dev/badge/instructions/danyuchn/pii-guard/agents-md.svg" alt="Measured on agentmods" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.01413 | $0.01413 |
| Opus 5 | $0.00707 | $0.00707 |
| Sonnet 5 | $0.00283 | $0.00283 |
| Haiku 4.5 | $0.00141 | $0.00141 |
Grade A, and why
pii-guard AGENTS.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 84 lines — stays where its author put it; the contents beside it link to each section on GitHub.
AGENTS.md
This file provides guidance to coding agents (Claude Code, Codex, and others) working in this repository. CLAUDE.md is a symlink to this file.
Project Overview
pii-guard-tw — 繁體中文(台灣)個人資料去識別化工具。將文件中的 PII 替換為佔位符後送 AI 處理,完成後自動還原,確保真實資料全程不離開本機。
Tech Stack
- Language: Python 3.11+
- Package manager:
uv(必用uv run/uvx,禁用 pip) - PII framework: Microsoft Presidio(偵測 + 匿名化 + 還原)
- Chinese NER:
ckiplab/bert-base-chinese-ner(中研院,繁體中文) - Taiwan PII Regex: 自建
PatternRecognizer(身分證、手機、市話、統一編號) - Pipeline: LangChain
PresidioReversibleAnonymizer(mapping table 序列化/還原)
Architecture
原始文件
↓ [偵測層] CKIP NER + 台灣 Regex PatternRecognizer
↓ [替換層] 建立 mapping table → 去識別化文本
↓ [LLM 處理] AI 只看到佔位符版本
↓ [還原層] reverse replace → 還原後 AI 回答
關鍵原則:LLM 只做輔助偵測,替換與還原全由程式碼完成,decode 可靠性 100%。
Commands
# 安裝依賴
uv sync
# 執行主程式(CLI)
uv run python -m pii_guard <input_file>
# 執行測試
uv run pytest
# 執行單一測試
uv run pytest tests/test_recognizers.py::test_tw_id_number -v
# 型別檢查
uv run mypy src/
# Lint
uv run ruff check src/
PII Types Supported
| 類型 | 方式 | Pattern |
|---|---|---|
| 人名、組織、地名 | CKIP NER | BERT 模型推論 |
| 身分證字號 | Regex | [A-Z][12]\d{8} |
| 外籍居留證 | Regex | [A-Z][A-D89]\d{8} |
| 手機號碼(本地) | Regex | 09\d{8} |
| 手機號碼(+886) | Regex | \+886[-\s]?9\d{2}... |
| 市話 | Regex | 0[2-8]\d{7,8} |
| 統一編號 | Regex + context | \d{8} |
| Email、信用卡 | Presidio 內建(zh 覆寫) | — |
| 車牌 | Regex + context | [A-Z]{2,3}-\d{4} / \d{3,4}-[A-Z]{2} |
| 出生日期 | Regex + context | 民國 \d{2,3}年... / 西元 \d{4}[-/.] |
| 銀行帳號 | Regex + context | \d{12,16} |
Development Roadmap
- Phase 1 MVP ✅ 2026-03-30:Presidio + 台灣 Regex 8 種,MCP Server 介面,89 tests
- Phase 2 ✅ 2026-03-30:CKIP BERT NER(人名/組織/地名)整合驗證,+4 種 PII 類型,MCP smoke test,152 tests total
- Phase 3 ✅ 2026-03-30,2026-08-21 移除:Ollama Qwen2.5:1.5b LLM fallback 偵測層。改由
pii-safe-documentsskill 的多次取樣稽核取代;舊層無語料證據且與新層並存會讓使用者選錯。要在 CLI 端補回稽核,做法是下沉 skill 那套,不是重新啟用這個。 - Phase 4 ✅ 2026-03-30:eval corpus 53 筆標註語料 + precision/recall/F1 框架,修復 5 個偵測問題。2026-08-31 實跑
uv run pytest tests/eval/ -v -m eval -s:Regex 49 TP / 0 FP / 0 FN(F1=100%),Full CKIP 62 TP / 1 FP / 2 FN(F1=97.6%)。同日把 loc-001 的標註由 LOCATION 更正為 TW_ADDRESS,並在類別正規化前依 raw type 排除 NER-only 類型,使結構化地址確實貢獻 Regex TP;另修正 TW_PASSWORD 關鍵字邊界,避免把 "passport" 的 "port" 誤判為密碼。 - Phase 5 ✅:
pii-safe-documentsskill(顯式觸發、可逆、主 agent 隔離)。早期的 PreToolUse hook 已退役,見examples/claude-code-hook/。 - Phase 6 ✅ 2026-03-31:多格式檔案支援(xlsx/docx/pdf)CLI + MCP,file_handlers 模組,MIT LICENSE
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- yesterday Changed · +91 tokens per session 83c724cdb9fc
- 6d ago First seen · 84 lines · 1,322 tokens per session scan A ad5ce5c898a2
pii-guard AGENTS.md is an instructions file published in the GitHub repository danyuchn/pii-guard (128 stars, last pushed 4d ago), licensed MIT. It adds 1,413 tokens to every session, about $0.0071 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other instructions, from other repositories
rizzo-pii CLAUDE.md
Instructions for Rizzo-AI-Academy/rizzo-pii, covering claude.md, cos'è questo progetto, ambiente — vincoli critici e non ovvi, mappa della repo and tassonomia: 22 tag (dettaglio in tassonomiatag.md).
docs_masked AGENTS.md
Instructions for kpshinnik/docs_masked, covering agents.md — правила работы в этом репозитории, инварианты, которые нельзя ломать, разработка, как добавить детектор and как добавить формат.
ollama AGENTS.md
AGENTS.md instructions for ollama/ollama, covering agents.md and building.
ollama CLAUDE.md
Claude Code instructions for ollama/ollama: See AGENTS.md for the shared agent instructions for this repository.
MaxKB CLAUDE.md
Claude Code instructions for 1Panel-dev/MaxKB, covering claude.md, project overview, development commands, database / static and architecture.
OllamaSharp AGENTS.md
Instructions for awaescher/OllamaSharp, covering agents.md — ollamasharp, project overview, how ollamasharp fits in the .net ai ecosystem, why this matters especially for tool use / function calling and build / test / lint commands.