# Patterns

A pattern is a saved filter over a run's canary readings and neurons, combined with any or all, that finds the runs in your history that show a concerning signal.

A pattern is a saved, named filter over a run's canary readings and activation-profile neurons that finds the runs in your history showing a signal you care about.

## When to use it

Use a pattern to filter your prompt history to the runs that tripped a canary family, lit up neurons labeled like "credential", or crossed an activation threshold in late layers. In CI, test each run of a suite against a pattern and fail the build on an unexpected match.

## How it works

1. Pick one from the library or save your own with [`POST /v1/trace/patterns`](https://provenanceauth.com/docs/api/patterns.md#post-v1-trace-patterns). The library has one curated pattern per [canary family](https://provenanceauth.com/docs/trace/concepts/canary-families.md), `pat_curated_<family>`.
2. A pattern is evaluated when you read, never when a run is recorded, so a new pattern covers your whole history at once. Pass `pattern` to the prompt history, a prompt's runs, a profile, a comparison or an attribution trace.
3. Each result says whether it matched, which visible neurons made it match, and one line per rule saying why.

1. **Run**: readings + profile
2. **Pattern**: rules, any or all
3. **Result**: matched, neurons, reasons

## The definition

A definition is `match` (`any` or `all`) and one to 16 rules:

| Rule `kind` | Fields | Matches when |
| --- | --- | --- |
| `family` | `family`, optional `min_score` | The family's reading tripped, or reached `min_score` |
| `neurons` | `refs`, optional `min_activation`, `min_count` | At least `min_count` of the refs are among the run's visible active neurons |
| `label` | `query`, optional `min_activation`, `min_count` | Visible active neurons have a registry label containing `query` |
| `activation` | `min`, optional `layers`, `pole`, `min_count` | Visible neurons reach `min`, within the layer range and pole |

```json
{
  "name": "Wire instructions in late layers",
  "definition": {
    "match": "all",
    "rules": [
      { "kind": "family", "family": "prompt_injection" },
      { "kind": "activation", "min": 1.5, "layers": [12, 23] }
    ]
  }
}
```

Neuron rules read the run's [activation profile](https://provenanceauth.com/docs/trace/concepts/activation-profiles.md); a run without one can still match a `family` rule. A masked neuron never matches any rule and never appears in the result, so a pattern can't be used to learn which neurons a curated family guards on.

A match means the run activated neurons associated with the pattern. A `family` rule's reason quotes the family's measured precision and recall.

## Related

- [Eval explorer](https://provenanceauth.com/docs/trace/guides/eval-explorer.md)
- [Activation profiles](https://provenanceauth.com/docs/trace/concepts/activation-profiles.md)
- [Canary families](https://provenanceauth.com/docs/trace/concepts/canary-families.md)
