Code calculates. The model judges. Policy decides.
Why I built JevPolicy, a TypeScript runtime that turns probabilistic LLM judgments into versioned, replayable decisions, and what it takes to change those decisions safely once they're in production.
On this page
The fastest way to put an LLM into an application is to let it decide. Route this ticket. Approve this request. Escalate this case. You write a prompt, parse the answer, and act on it.
That works right up until someone asks a question you can’t answer. Why was this ticket sent to billing? Would last week’s tickets have gone somewhere else under the new prompt? If we raise the urgency threshold, how many more cases land on a human? When the decision lives inside a prompt, the honest answer to all three is “we’d have to run it again and see.”
JevPolicy is my answer to that. It’s an open-source TypeScript runtime built on one split of responsibilities:
Code calculates. Jev judges. Policy decides.
Jev is a judgment model (typesafe-ai/jev) accessed through Vercel AI Gateway. JevPolicy never lets it make the decision. It asks Jev narrow, typed questions, normalizes the answers into signals, and hands those signals to ordered rules in a versioned YAML file. The rules decide.
Pipeline
A policy, read top to bottom#
The example in the repo routes support tickets. Here’s the core of it:
schema: jevpolicy/v1
name: support-routing
version: 1
decisions: [billing, technical, account, human_review]
facts:
authenticated: { type: boolean, required: true }
questions:
category:
type: choice
instructions: Which support category best matches this ticket?
criteria:
billing: Payment, refund, or charge problems
technical: Product or application problems
account: Login or account-management problems
urgent:
type: boolean
instructions: Does this support ticket require urgent attention?
criteria:
true: Requires immediate handling
false: Can follow the normal queue
complexity:
type: score
instructions: Rate how complex this ticket is to resolve.
criteria: [trivial, simple, moderate, complex, specialist]
preconditions:
- id: unauthenticated
when: { fact: authenticated, op: eq, value: false }
decision: human_review
rules:
- id: complex-and-urgent
when:
all:
- { signal: complexity, op: gte, value: 4 }
- { signal: urgent, op: gte, value: 0.70 }
decision: human_review
- id: billing-route
when: { signal: category, op: eq, value: billing }
decision: billing
# ...technical-route, account-route
fallback:
provider_error: human_review
provider_timeout: human_review
invalid_provider_response: human_review
no_match: human_review
A few things in there are deliberate.
Facts and signals are different things. authenticated is a fact: the application knows it, and nobody should ask a model about it. category, urgent, and complexity are signals: judgments that only make sense to ask a model for.
Preconditions run before the model is called. An unauthenticated ticket goes to a human without spending a single token. If a decision can be made deterministically, it should be, and it should be cheaper too.
Thresholds are explicit. urgent is a boolean question, but what comes back is a probability, and the rule says gte 0.70. There’s no hidden “anything above 0.5 counts as true.” If you want a threshold, you write it down, and it shows up in the diff when someone changes it.
Order is the policy. complex-and-urgent sits above billing-route, so a complex, urgent billing ticket goes to a human. Swap them and the same ticket goes to billing. That’s why the diff tool treats reordering as a change in its own right.
Failure is a decision too#
The most important lines in that file are the last five. A model call can time out, error, or return something that doesn’t parse. In a prompt-driven system, those cases tend to fall through to whatever the code does by default, which is how “the model was down” quietly becomes “every request was approved.”
In JevPolicy, provider timeouts, invalid responses, and other provider failures map only to explicit fallbacks in the policy. They never silently become an allow. The same goes for “no rule matched.” And if your own code aborts the call, that rejects rather than being recorded as a provider failure, so the decision log doesn’t blame the model for something the caller did.
Record once, replay forever#
Each evaluation can be appended to a JSONL decision log. A record holds the declared facts and, for successful evaluations, the normalized signals, each tagged with a fingerprint of the question that produced it.
Those fingerprints are what make replay possible. Change the rules, keep the questions, and you can re-run every recorded decision against the new policy without calling the model again:
$ npx jevpolicy replay decisions.jsonl --policy ./policy.yaml --jsonIf you change a question’s wording, its fingerprint changes, and replay refuses to reuse the old signal. That’s correct: the model was asked something different, so its old answer doesn’t apply.
Raw state recording defaults to none. A policy can opt into full recording, or redacted when the application supplies a redaction hook. Decision logs are still sensitive, so the README says to keep them out of version control. And if a write to the log fails, the error carries the decision that was already computed, so the application doesn’t lose it.
Changing a policy without guessing#
Most of the work after 0.1.0 went into one problem: how do you change a policy that’s already making real decisions?
- Edit the prompt, deploy, watch the dashboard
- No record of what the old version would have done
- Threshold changes hidden inside wording
- Find out it was worse after users do
- Semantic diff shows exactly which rules changed
- Replay old decisions against the new policy offline
- Shadow mode runs the candidate on live traffic
- Calibrate both against real outcomes
Semantic diff. jevpolicy diff compares two policies without calling a provider. Rules and preconditions are matched by ID, and reordering is reported separately, because reordering changes which rule wins.
Shadow evaluation. A candidate policy runs on the same live provider response as the active one. Both decisions are recorded, but only the active one should drive side effects. A compatible pair has to share the same fact contract, question names, and question fingerprints; anything else is rejected before the model is called, so the comparison is always apples to apples.
$ npm run cli -- evaluate examples/support-routing.policy.yaml \ --state examples/support-routing.state.json \ --shadow-policy examples/support-routing.candidate.policy.yaml
Measuring whether it’s right#
Replay and shadow mode tell you what changed. They don’t tell you whether the change was better. For that you need ground truth, and ground truth usually arrives later: the ticket gets resolved, and now you know what it really was.
JevPolicy keeps those outcomes in a separate append-only file, so the original decision log stays immutable. Duplicate IDs and outcomes that point at unknown decisions are rejected, so the join can’t silently go wrong. From there, three offline reports:
| Report | Answers |
|---|---|
calibrate | Accuracy, per-label precision and recall, and which decisions turned into which outcomes |
confidence | How decision accuracy changes across probability bands |
frequency | Which rules and preconditions are actually producing decisions |
Shadow records are scored against the outcome of the live decision they ran alongside, so outcomes only ever need to reference live decisions. Undefined ratios come back as null, never NaN.
Small things that took real care#
- Prototype names are rejected. Declaring a fact or choice value called
constructorused to be accepted. Since 0.3.0, built-in object property names are refused, so a policy can’t accidentally collide with JavaScript’s object model. - Telemetry that can’t leak. The optional OpenTelemetry observer emits decision spans, counters, and duration histograms. State, facts, signals, prompts, and provider responses are excluded by design, and an observer failure can never change or reject a decision that was already made.
- Mocked and live contract tests. The Vercel adapter has mocked contract tests in CI and an opt-in live test against the real model.
- signal types: boolean, choice, score
- 3
- explicit fallbacks, no silent allow
- 4
- model calls needed to replay a decision
- 0
Who owns what#
The README ends with a responsibility boundary, and it’s the part I’d show anyone evaluating whether to use this:
| Vercel AI Gateway | JevPolicy | Your application |
|---|---|---|
| Auth and access to Jev | Policy as code, preconditions, questions | Side effects and authorization |
| Model and provider routing | Signal normalization and thresholds | Payments and business transactions |
| Usage and spend visibility | Rules, fallbacks, traces, record and replay | Notifications and tool execution |
Try it#
npm install @sanoy24/jevpolicy
npx jevpolicy validate ./policy.yaml
Validation, diff, replay, and every report run fully offline. Live evaluation needs an AI_GATEWAY_API_KEY. The repo has the support-routing example ready to run, including a candidate policy to diff and shadow against.
If there’s one idea worth taking away even without the library: let the model answer questions, and keep the decision somewhere you can read, diff, and replay.
The project
JevPolicy: Deterministic Decisions from LLM Judgments
An open-source TypeScript decision runtime that turns probabilistic LLM judgments into versioned, deterministic, replayable, and observable application decisions.
Personal project
Published on npm, with replay and shadow evaluation