Rules
Rules live in .prism/rules.json at your project root. prism check and the agent hooks enforce it. prism init generates a starter; prism pull fetches your team’s version from the dashboard. Same file, same schema.
File format
Version 1 schema. An object with a top-level rules array:
{
"version": 1,
"rules": [
{
"id": "styling/no-magenta",
"category": "styling",
"severity": "block",
"extensions": [".tsx"],
"instruction": "Use the design system palette. Never hardcode magenta.",
"check": {
"type": "forbidden_pattern",
"pattern": "#ff00ff",
"message": "Use the design system palette, not magenta."
}
}
]
}This exact example parses and fires — it follows the validator in the CLI source (src/rules/parse.ts).
Rule fields:
| Field | Required | Description |
|---|---|---|
id | Yes | Non-empty string. Convention: category/name |
category | Yes | One of the four categories below |
severity | No | block or warn. Defaults to warn |
instruction | No | Advisory text for the agent (no check needed) |
extensions | No | File extensions the rule covers (e.g. [".tsx", ".ts"]). Normalized with a leading dot |
check | No | The machine-checkable block (types below). Without it the rule is advisory only |
Categories
Exactly four. Any other value fails validation:
| Category | Purpose |
|---|---|
architecture | File structure, imports, patterns |
styling | Design tokens, CSS, colors |
security | Auth, validation, dangerous calls |
testing | Test placement, frameworks |
Use only the four categories above. An invalid category (or any other
schema error) fails validation — and because hook mode fails open, a
broken rules.json means the hook logs the error to stderr and skips
enforcement entirely until the file is fixed. Run prism check <file>
by hand after editing rules to confirm the file still parses.
Severities
| Severity | Effect |
|---|---|
block | Hook exits with code 2 and returns a correction to the agent. The agent must fix the violation |
warn | Reported as a finding, never stops the agent (default when omitted) |
Check types
All seven types below are implemented and validated by the CLI (src/rules/types.ts).
forbidden_pattern
Flags any file matching a regular expression.
{
"type": "forbidden_pattern",
"pattern": "#[0-9a-fA-F]{6}",
"flags": "g",
"allowlist": ["#000000", "#ffffff"],
"fix": "Use a design token variable instead of a hex literal.",
"message": "Hardcoded hex colors are not allowed."
}| Field | Required | Description |
|---|---|---|
pattern | Yes | Regular expression source |
flags | No | Regex flags |
allowlist | No | Exact matches to ignore |
fix | No | Suggested replacement shown in the correction |
message | No | Custom message |
required_token
Requires raw CSS values to be written as design tokens.
{
"type": "required_token",
"tokenSet": "colors",
"tokenMap": {
"#06b6d4": "var(--color-primary)",
"#050505": "var(--color-void)"
}
}tokenMap maps each raw value to the token that must replace it. Generated by prism init from your own CSS custom properties.
banned_import
Blocks specific import specifiers.
{
"type": "banned_import",
"specifiers": ["lodash", "moment"],
"message": "Use the lightweight utils instead."
}arbitrary_value
Flags arbitrary bracket values in Tailwind utilities (e.g. w-[13px]).
{
"type": "arbitrary_value",
"properties": ["width", "height", "p", "m"]
}properties are Tailwind utility names (lowercase letters, digits, dashes).
naming_pattern
The file’s base name (without extension) must match the pattern.
{
"type": "naming_pattern",
"pattern": "^[A-Z][A-Za-z0-9]*$",
"message": "React components must be PascalCase."
}file_placement
Files matching matchPattern must live inside directory.
{
"type": "file_placement",
"matchPattern": "^use[A-Z]",
"directory": "src/hooks"
}required_import
Every covered file must import the specifier. Optionally scoped by path.
{
"type": "required_import",
"specifier": "next-env-types",
"includePattern": "\\.d\\.ts$"
}The inverse of banned_import.
Example rule packs
The CLI repository ships executable example packs under examples/ (Flutter, Kotlin, Python). They are loaded by the test suite, so every convention they encode is proven to fire. For instance, the Python pack blocks breakpoint() at block severity and requires snake_case module names.
How findings are reported
prism check <file> prints findings and exits 1 when blocking violations exist, 0 when clean. Hook mode writes a correction message to stderr and exits 2. Every hook run appends one line to .prism/activity.log (observability only).
Related
- Quick Start — Edit a rule and see it fire
- Hooks and IDE Setup — How enforcement wires into agents
- Dashboard Guide — Managing rules in the cloud