rule-audit
AGENTS.md3 starsChanged 3 months agoApache-2.0View on GitHub
Guidance for AI agents (Claude Code, Cursor, Aider, Continue, etc.) editing this repo. Human reviewers read this too. Short, imperative, load-bearing. rule-audit — a static analyzer for AI system prompts. Input: raw prompt text. Output: structured report of contradictions, coverage gaps, priority ambiguities, meta-paradoxes, absoluteness issues, and concrete edge-case attack scenarios. Pure Python. Zero LLM dependency. Zero network calls. Runs in milliseconds. Think: bandit / semgrep — but for system prompts. Part of the Hermes Labs reliability stack: - rule-audit…
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 35,266 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository3 other files it gives its agents.
- .claude/CLAUDE.mdCLAUDE.md
- llms.txtllms.txt
- rule-auditSkill
The file
We split this AGENTS.md into the rules it gives an agent
12 rules. About 0 are common, 0 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Read .claude/CLAUDE.md — project conventions, adding detectors, adding clusters.
- Very specific: line 26
Read SPEC.md — data model, detector algorithms, severity calibration.
- Very specific: line 27
Read ROADMAP.md — what's in v0.1.0, what's planned for v0.2+.
- Very specific: line 28
Read benchmarks/README.md — expected finding counts per sample prompt.
- Very specific: line 81
Write a detector function in analyzer.py: _is_<kind>_contradiction(rule_a, rule_b) -> Optional[Contradiction] (or a result type you add).
- Very specific: line 82
If it's a new result class: add a dataclass alongside Contradiction / Gap / etc.
- Very specific: line 84
Add an edge-case generator in rule_audit/edge_cases.py.
- Very specific: line 86
Write tests in tests/test_analyzer.py.
- Very specific: line 122
Don't add an LLM dependency to the core library.
- Very specific: line 123
Don't silently change detector output.
- Very specific: line 124
Don't break the exit-code contract.
- Very specific: line 125
Don't add emojis to library code.
≈ “Common” is an estimate: at least 1 in 5 of the 45,344 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Owner: Hermes Labs - https://hermes-labs.ai
AGENTS.md — rule-audit
Guidance for AI agents (Claude Code, Cursor, Aider, Continue, etc.) editing this repo.
Human reviewers read this too. Short, imperative, load-bearing.
What this repo is
rule-audit — a static analyzer for AI system prompts. Input: raw prompt text. Output: structured report of contradictions, coverage gaps, priority ambiguities, meta-paradoxes, absoluteness issues, and concrete edge-case attack scenarios.
Pure Python. Zero LLM dependency. Zero network calls. Runs in milliseconds.
Think: bandit / semgrep — but for system prompts.
Part of the Hermes Labs reliability stack:
rule-audit— static analysis of prompt logical content (this repo)lintlang— static linter for agent configs and tool descriptions (structure, not logical content) — complementaryhermes-jailbench— dynamic jailbreak regression suite for live endpoints — complementarycolony-probe— prompt-confidentiality audit (system-prompt reconstruction via multi-turn probing)
Start here
- Read
.claude/CLAUDE.md— project conventions, adding detectors, adding clusters. - Read
SPEC.md— data model, detector algorithms, severity calibration. - Read
ROADMAP.md— what's in v0.1.0, what's planned for v0.2+. - Read
benchmarks/README.md— expected finding counts per sample prompt.
Public API
Three entry points. These form the stable surface — breaking changes require a major version bump.
from rule_audit import audit, audit_file, AuditReport
# Inline string
report: AuditReport = audit("You are helpful. You must never lie. Always answer.")
# From file
report: AuditReport = audit_file("samples/basic_assistant.txt")
# AuditReport surface
report.summary() # str — terminal summary
report.to_markdown() # str — full markdown report
report.to_dict() # dict — JSON-serializable
report.to_json() # str — JSON
report.risk_score # float — 0..100 composite
report.risk_label # "LOW" | "MEDIUM" | "HIGH" | "CRITICAL"
report.edge_cases # list[EdgeCase]
report.result.rules # list[Rule]
report.result.contradictions # list[Contradiction]
report.result.gaps # list[Gap]
report.result.priority_ambiguities # list[PriorityAmbiguity]
report.result.meta_paradoxes # list[MetaParadox]
report.result.absoluteness_issues # list[AbsolutenessIssue]CLI: rule-audit [prompt] [--file PATH] [--format markdown|json|summary] [--min-severity high|medium|low] [--verbose]
Exit codes: 0 = LOW/MEDIUM, 2 = HIGH/CRITICAL, 1 = error.
Extension points
Add a new keyword cluster
Edit _KEYWORD_CLUSTERS in rule_audit/analyzer.py. Each cluster is a domain name mapped to a list of lowercase keyword stems.
_KEYWORD_CLUSTERS: dict[str, list[str]] = {
"harm": ["harm", "dangerous", ...],
...
"your_new_cluster": ["keyword1", "keyword2", ...],
}Rules that share any cluster are considered "about the same topic" for contradiction detection.
Add a new detector
- Write a detector function in
analyzer.py:_is_<kind>_contradiction(rule_a, rule_b) -> Optional[Contradiction](or a result type you add). - If it's a new result class: add a dataclass alongside
Contradiction/Gap/ etc. and include it inAnalysisResult. - Register the detector in
find_contradictions()(or the top-levelanalyze()). - Add an edge-case generator in
rule_audit/edge_cases.py. - Render it in
rule_audit/report.py(add a section renderer, wire it intoto_markdown()andto_dict()). - Write tests in
tests/test_analyzer.py. Tests are required. The CI matrix runs Python 3.9 through 3.12.
Adjust severity
See SPEC.md §4 for calibration. Change risk weights in AnalysisResult.risk_score (analyzer.py) — update the thresholds in AuditReport.risk_label (report.py) when a weight change moves a sample prompt across a label boundary.
Project structure
rule_audit/
__init__.py # Public API: audit(), audit_file(), AuditReport
__main__.py # python -m rule_audit entry
parser.py # Sentence splitting, modality detection, Rule objects
analyzer.py # Contradiction / gap / priority / meta / absoluteness detectors
edge_cases.py # Concrete scenario generator from AnalysisResult
report.py # AuditReport + Markdown / JSON renderers
cli.py # Argparse CLI
evidence.py # Result envelope emitter (python -m rule_audit.evidence); no detection logic
py.typed # PEP 561 type-hint marker
tests/ # pytest — the full suite, all pure Python
samples/ # 5 real-world-style system prompts
benchmarks/ # Expected finding counts per sample
launch/ # Launch post drafts (do not ship to PyPI)Conventions
- Pure Python stdlib only. No runtime dependencies. If you're tempted to add one, don't.
- Rule objects are immutable dataclasses. Parser produces them, analyzer consumes them.
- Public functions have type hints and "Added in vX.Y.Z" docstrings.
- Library code uses
logging.getLogger(__name__). Onlycli.pycallsprint(). - Tests live in
tests/. Benchmarks live inbenchmarks/. Launch copy lives inlaunch/.
Don't
- Don't add an LLM dependency to the core library. v0.2 will add an optional
--llmplugin; that is not v0.1. - Don't silently change detector output.
tests/test_benchmark.pyasserts finding counts againstsamples/*.txt— if you legitimately shift counts, update the asserts andbenchmarks/README.mdin the same PR. - Don't break the exit-code contract.
rule-auditreturning2on HIGH/CRITICAL is load-bearing for CI integrations. - Don't add emojis to library code. (The markdown renderer uses a handful of status glyphs; that's scoped to
report.py.)
Cross-product context
When rule-audit flags a HIGH-severity contradiction, the suggested edge-case scenario is a starting point for dynamic verification — hermes-jailbench tests whether the flaw is reachable against a live endpoint. The pipeline: static analysis surfaces candidate flaws, dynamic testing checks reachability. Don't reinvent dynamic testing in this repo.
Home: https://hermes-labs.ai
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

