Prism · guide

For a model

The grammar as JSON Schema, a smaller one for a mapping, and what to do with what a model writes.

Install it
pnpm add @niscorp/prism @niscorp/strata zod
Step 1 of 3

The grammar, as a schema

Prism’s schema is written in Zod, and the JSON Schema made from it is what a model is handed. Nothing explains the grammar a second time.

The grammar, as a schema
import { MAPPING_OPS, OP_KEYS, evaluateSafe, validate } from '@niscorp/prism';
import { getConfigJsonSchema, getProfileJsonSchema } from '@niscorp/prism';

const whole = JSON.stringify(getConfigJsonSchema());
console.log(OP_KEYS.length, 'operators,', whole.length, 'characters of schema');
Step 2 of 3

A profile

A model that maps rows into a shape needs fewer operators than there are. A profile is the schema documenting only the operators you name. It narrows what a prompt teaches, never what Prism accepts.

A profile
const mapping = JSON.stringify(getProfileJsonSchema(MAPPING_OPS));
console.log(MAPPING_OPS.length, 'operators,', mapping.length, 'characters of schema');
Step 3 of 3

What a model wrote

What comes back is text. Parse it, hold it to the schema, and only then run it: validate names what is wrong, and evaluateSafe never throws.

What a model wrote
const written = '{ "name": { "$ref": "$.member.name" }, "admit": { "$length": { "$ref": "$.seats" } } }';
const config = JSON.parse(written);
const checked = validate(config);
if (checked.ok) {
  console.log(evaluateSafe(checked.data, { member: { name: 'Grace' }, seats: ['C4', 'C5'] }));
}
Then

Run it.

How large the whole grammar is as a schema, how much smaller the mapping profile is, and a config written as text, checked and run.

Run it
npx tsx schema.mts
It prints
75 operators, 36538 characters of schema
55 operators, 26600 characters of schema
{ ok: true, data: { name: 'Grace', admit: 2 } }