# Structural checks

Neurarch runs **50 structural checks**: 6 guardrail gates, 37 advisor rules, and 7 edit checks that compare a change with what it was changed from. They exist because architecture bugs do not fail in code review; they fail at forward time on a GPU you already paid for, sometimes hours into a run.

## The two layers

**Guardrail gates (6)** sit between the AI agent and your model. Before any agent action touches the graph they run impact analysis (blast radius of the change), a parameter-explosion check, cycle detection, orphan detection, shape inference on the sandboxed result, and per-parameter range validation. A gate can block the edit outright; the agent then sees why and adjusts.

**Advisor rules (35)** lint the graph live as you build, no agent involved. They surface as colored dots on the affected layer (red error, amber warning, blue note), in the Architecture Advisor panel, and in the pre-flight report. Where credible, each rule cites a paper or the PyTorch docs.

The full list, rule by rule with trigger conditions: <https://neurarch.com/rules.html>.

## What the shape engine catches

Sub-millisecond shape propagation over the typed graph flags, among others:

- attention `embedDim % numHeads != 0` (head dim would be fractional)
- grouped-query attention where `numHeads % numKVHeads != 0`
- a Linear whose declared `inFeatures` does not match the upstream output width
- element-wise merges (residuals, adds) whose parent shapes disagree
- shape-invalid regions introduced by a specific edit, attributed to the first layer that introduces them

## Does the verdict track reality?

Measured, not asserted. We generated clean reference architectures plus systematically corrupted variants, built every graph as a real PyTorch model, and cross-tabulated verifier verdict against runtime behavior: 264 graphs, two seeds, torch 2.8.

| Verifier verdict | n | PyTorch forward | Makes training progress |
|---|---|---|---|
| PASS (clean) | 80 | 100% ok | 90% |
| BLOCKED | 96 | 0% ok (96/96 crash) | 0% |

"Makes training progress" means loss fell at least 20% in 60 steps; it is a trainability probe, not a quality claim. Reproduce from the open benchmark repo: <https://github.com/neurarch-ai/neurarch-arch-bench>. Worked examples with the exact PyTorch errors: <https://neurarch.com/caught-bugs.html>.

### Grounded, all the way to a finished run

The 264-graph study probes one forward pass. The grounded benchmark split goes the rest of the way: frontier models design architectures against dataset-true tasks, and every design the verifier passes (plus an audited human reference per task) is trained to completion with the production trainer on a managed GPU. Latest campaign: 24/24 verifier-passed graphs trained end-to-end, zero crashes. Several statically-clean designs still trained to poor metrics, which is the failure class no static check can see by construction; grounding exists to catch exactly that, and each run adds a graded (design, outcome) pair to the corpus. Method, per-run table, and honest limits: `scripts/rl-benchmark/GROUNDED.md` in the main repo.

## Cost

0.27 ms per verified edit on a 47-layer graph (0.05 ms on a 6-layer one), one laptop core, no GPU, no LLM call. The number is pinned by a CI test that fails if it stops being true.
