> For the complete documentation index, see [llms.txt](https://docs.frayme.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.frayme.ai/components/validation.md).

# Validation

Validate a stream of spec operations — or an already-compiled spec — against the Frayme catalog, exactly the way the API gates every generation before it renders.

```ts
import { validatePair, compileOps, validateSpec } from '@frayme/catalog/validate';

// End-to-end: parse JSONL operations, compile, validate.
const result = validatePair(opsJsonl);
if (!result.valid) {
  console.error(result.failureCategory, result.errors);
}
```

## The three functions

* **`compileOps(opsJsonl)`** — stage 1+2: parses each JSONL line and replays it through the stream compiler. Returns `{ spec }` or `{ failure: { errors, failureCategory } }`.
* **`validateSpec(spec, opts?)`** — stage 3: validates an already-compiled spec (component types, prop shapes, referential integrity — no dangling `root`, no missing `children`). Use this on the streaming path, where the spec is compiled incrementally.
* **`validatePair(opsJsonl, opts?)`** — convenience: `validateSpec(compileOps(opsJsonl))`.

Both validators accept an options object: `{ resolution: true }` additionally runs the render-resolution gate (binding syntax, directive shapes, action kinds, value safety) — recommended for authoring and QA pipelines. `{ catalog }` validates against an extended catalog from `extendCatalog()` when you bring custom components.

## PairValidationResult

```ts
interface PairValidationResult {
  valid: boolean;
  errors: string[];
  warnings: string[];
  spec?: FraymeSpec; // present when valid — the compiled spec, interactivity intact
  failureCategory?: FailureCategory; // present when invalid
}
```

## FailureCategory

Branch on the category, not the error strings:

| Category                    | Meaning                                                              |
| --------------------------- | -------------------------------------------------------------------- |
| `empty_input`               | The operations string contained no non-blank lines.                  |
| `malformed_jsonl`           | One or more lines did not parse as JSON.                             |
| `compiler_error`            | The stream compiler threw while replaying the operations.            |
| `empty_spec`                | Compilation produced no spec (or a spec with no root/elements).      |
| `catalog_validation_failed` | A component type, prop shape, or spec structure check failed.        |
| `unknown_element_key`       | An element carries a field the renderer does not recognise.          |
| `invalid_binding`           | A state binding or template expression is malformed.                 |
| `invalid_directive`         | A `visible`/`watch`/conditional directive has the wrong shape.       |
| `invalid_action_kind`       | A spec-declared action has an unknown `kind`.                        |
| `resource_limit`            | The spec exceeds a size or depth limit.                              |
| `unsafe_value`              | A color/dimension prop carries a value the safety validators reject. |

## Validating a compiled spec directly

```ts
import { validateSpec } from '@frayme/catalog/validate';

const result = validateSpec({
  root: 'card',
  elements: {
    card: { type: 'Card', props: { title: 'Overview' } },
  },
}, { resolution: true });

result.valid; // true
```

Bring-your-own-component specs get their custom props checked by `validateManifestProps(spec, compiledManifests)` — built-in element types are ignored there; the catalog gate above covers them.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.frayme.ai/components/validation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
