> ## Documentation Index
> Fetch the complete documentation index at: https://glassray.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Rules

> A rule is one expected behaviour of a flow - read from your code, or promoted from a confirmed deviation - and the thing a deviation is found against.

A **rule** is one expected behaviour of a [flow](/docs/flows) - "always cite a source before answering", "never issue a refund over \$500 without approval", "retry a failed tool call at most twice". A flow's rules are its **spec**: the set of things Glassray checks every trace against, and the reason a [deviation](/docs/deviations) exists in the first place.

## Where rules come from

<CardGroup cols={2}>
  <Card title="Read from code" icon="code">
    Most rules come straight from your codebase - found during a code scan and anchored to the file and symbol that enforces them, with the enforcing snippet attached so you can see the ground truth.
  </Card>

  <Card title="Promoted from a deviation" icon="arrow-up-from-line">
    A confirmed deviation that isn't grounded in code yet can be **promoted** into a rule of its own - so Glassray starts watching for it even before the code catches up. A promoted rule is marked "not in code" until a later scan finds the matching code, or you merge it into one that already exists.
  </Card>
</CardGroup>

## Watched vs. archived

A rule is either **watched** or **archived**:

* **Watched** - judged on every trace. A trace that breaks it surfaces as a deviation.
* **Archived** - retired. No longer judged, and its backing deviations return to the unmatched pool.

Archiving isn't deletion - a retired rule can be watched again later. Use it for a behaviour that's no longer expected (a feature was removed, a policy changed) rather than one that's simply wrong; a rule you promoted by mistake should be **removed** instead (see below).

## Keeping rules and deviations in sync

A deviation is always found *against* a rule, but the two can drift apart - a deviation Glassray couldn't confidently match to one of your existing rules shows up as **unmatched**. From there you can:

* **Link it to an existing rule** it actually violates, instead of leaving it stranded.
* **Promote it into a new rule**, if it's a real behaviour nothing currently covers.
* **Dismiss it as noise**, if it isn't a real behaviour at all.

Glassray also runs this matching automatically in the background - re-checking unmatched deviations against your rules by wording, then meaning, so most resolve themselves without you doing anything. A rule can also turn out to be a duplicate of another (often after being promoted); **merge** it into the one that should stay, and its deviations follow the link.

<Tip>
  See a flow's rules under its **What it should do** tab, or over [MCP](/docs/mcp-server) as part of the flow's rule list.
</Tip>
