← Jev From First Principles

The Decision Specification

What must a declarative decision specification say, so a validator can catch mistakes the library API cannot? A DecisionSpec, five bug classes, and an honest account of what 5/5 detection does and does not show.

This chapter is model-free: a declarative DecisionSpec and a validator, with five seeded bug classes and a reported detection rate. No model runs; the numbers are the validator’s own outputs on specifications written by the same person who wrote the validator, so they show what the checks do, not what bugs people make.

The question

Every chapter so far asked a provider a decision through the library API. The API checks a single call in isolation: is the question well formed, is the answer in the allowed set, is the confidence between 0 and 1. But a decision in a program has a life beyond one call. It may abstain, and the abstained request must go somewhere. It may fall back to another provider, and that provider must exist. Each answer class must have a consequence. Its thresholds must agree with each other and with its risk target.

None of that fits in one call, and none of it is checked by the call’s own validation. These are mistakes in how a decision is used, and they are the kind a reviewer misses because every line looks fine alone.

Parts V to VII built the constructs that use decisions: if decide, match decide, where decide, pipelines and graphs. Part VIII measured routing and cascades. A language needs somewhere to say all this in one place, so that a tool can check it before anything runs. That place is a specification.

This chapter asks: what must a declarative decision specification say, so a validator can catch mistakes the library API cannot?

You will leave with a concrete DecisionSpec type, five named bug classes, a validator you can run, and a clear sense of what its detection rate permits you to conclude. That last part is the point. A validator that catches the bugs its author thought of is a low bar, and this chapter says so.

What the literature gives you

Cedar is used for §2-§3, not its evaluation sections. Model Cards is cited only for its abstract.

Source What is declared What is checked What it means for us
Cedar, Cutler et al. (2024), §2.5, §3.4-§3.6 Authorisation policies over principal, action, resource Optional validation against a schema typechecks each policy for every allowed action; a soundness theorem says a policy that typechecks evaluates without error on conforming data (§2.4, §3.5). A symbolic compiler to SMT answers questions such as policy equivalence (§2.6) The closest prior art: a declarative language plus a validator that runs before the policy does. Two lessons: validation is optional and designed not to get in the way, and its guarantee is a stated theorem, which ours is not
Ludwig, Molino et al. (2019), §2.1, §3.1-§3.2 Input and output features, each with a name and a type, in a YAML configuration The paper describes defaults for missing values and does not describe checking a configuration for contradictions The type does real work, since it selects the encoder, decoder and metrics. But Ludwig is evidence for type-driven construction, not for validation. We should not cite it as a validator
Model Cards, Mitchell et al. (2019) A short document: intended use, evaluation conditions, caveats Nothing is machine-checked; it is documentation for people The analogy is to the content a spec should record (what the decision is for), not to enforcement

Three observations follow.

First, the pattern is established and our contribution is small. Cedar already shows that a declarative language, a schema and a pre-run validator make a class of errors detectable early. The chapter does not claim novelty for that pattern; it claims only that decisions have their own errors to detect.

Second, a guarantee needs a proof or a test, and we have a test. Cedar’s soundness theorem was machine-checked in Lean and complemented by differential testing against the implementation (§3.5-§3.6). Our validator has unit tests and a seeded-bug experiment. It carries no soundness claim and makes none.

Third, Cedar’s design principle is a constraint on us. The abstract says the validator helps writers “avoid mistakes, but not get in their way”. A decision validator that rejects specifications whose meaning is subtle would be worse than none. That is the Language book’s warning, quoted below, in a concrete setting.

The hypothesis and prior work

Our starting hypothesis (HYPOTHESIS, preregistered) is that a typed declarative spec makes a declared class of authoring bugs detectable at authoring time.

Read it narrowly. It says declared classes only. It makes no claim about bugs people actually make, no claim about false positives beyond the cases tried, and no claim that the classes are the right ones.

The build

Decision flow for Chapter 32

src/arbiter/spec.py defines the declarative spec and the validator. A DecisionSpec names the decision, its typed inputs, its answer classes (each with a description and a handler), whether it may abstain and where abstentions go, a fallback chain of providers, a keep threshold and an abstain threshold, a risk target, and whether evidence is required. validate(spec, provider_names) takes the registry of providers as a second argument. That argument is the point: the validator can check the fallback chain only because it knows which providers exist, something a single library call does not.

from arbiter.spec import AnswerClass, DecisionSpec, validate
# 1. A clean spec passes.
print("1. a clean spec")
clean = DecisionSpec(
    name="policy", inputs=("article",),
    answer_classes=(AnswerClass("publish", "publish", "publish"),
                    AnswerClass("reject", "reject", "reject")),
    abstention=True, abstention_route="human",
    fallback_chain=("rule", "judge", "human"),
    keep_threshold=0.9, abstain_threshold=0.4, risk_target=0.1,
    evidence_required=True,
)
print(f"   issues = {validate(clean, frozenset({'rule','judge','human'}))}")
# 2. The same spec, missing its abstention route: B1.
print("2. missing abstention route")
broken = DecisionSpec(clean.name, clean.inputs, clean.answer_classes,
                      True, None, clean.fallback_chain,
                      clean.keep_threshold, clean.abstain_threshold,
                      clean.risk_target, clean.evidence_required)
print(f"   issues = {[i.code for i in validate(broken, frozenset({'rule','judge','human'}))]}")
1. a clean spec
   issues = []
2. missing abstention route
   issues = ['B1']

Run it with python examples/ch32-the-decision-specification/walkthrough_ch32.py. The second spec differs from the first in exactly one field, the abstention route. Everything else is identical, which is what makes the failure legible. The spec says “this decision may abstain” and names nowhere for the abstained request to go. Chapter 11 gave abstention a meaning; this is the check that a program using it has answered the follow-up question.

The bug classes

The validator rejects five classes that a single library call cannot see (B4 covers two sub-conditions, thresholds and risk target):

Code Bug Why the API can’t catch it
B1 missing abstention route the API sees one call, not where the abstained request goes
B2 unreachable fallback (repeated or unknown provider) the API does not know the program’s provider registry
B3 overlapping answer sets (identical descriptions, or a name declared twice) the API checks shape, not whether two options mean the same thing
B4 inconsistent thresholds / risk outside (0,1] the API checks each value, not their joint coherence
B5 answer class with no handler (none, or empty) the API returns the answer; it does not know the caller must handle it
A DecisionSpec passes through a validator. Five named bug classes are rejected; a clean specification is accepted and handed to the compiler.
Figure 32.1. All five seeded classes are rejected. That shows the validator catches the bugs its author thought to seed, which is a low bar and is stated as one.

The run

run_ch32.py seeds one spec per bug class and a clean spec, and reports detection (results/ch32.jsonl):

bug class detected codes found
B1 yes [B1]
B2 yes [B2]
B3 yes [B3]
B4 yes [B4]
B5 yes [B5]
clean accepted []

Detection rate 5/5; the clean spec is accepted (no false positive). All six predictions hold: the validator catches each seeded bug and nothing it should not.

Read that carefully. The five bugs were written by the same author who wrote the validator, one per class, in the simplest possible form. The result confirms the validator does what it was written to do. It says nothing about whether the five classes cover the mistakes people make, how often they make them, or whether a subtler version of each slips through. The “no false positive” claim rests on one clean spec.

Where the validator falls short

A review pass that tried to break the validator on its own prose found gaps. In the original code, B2 was promised for “repeated or unknown provider” but checked unknown providers only from the second stage onward, and repeats only when adjacent. So ("ghost", "judge") and ("rule", "judge", "rule") both passed. The chapter’s seeded B2 case (("rule", "rule", "judge")) was adjacent and caught, which is exactly how a seeded test can miss a hole. The code is now fixed to check every stage and any repeat, and similarly B3 now also fires on a duplicated answer name, and B5 treats an empty handler string as missing. The 5/5 result is unchanged; results/ch32.jsonl is byte-identical before and after. Tests for these cases are in tests/spec/test_spec.py (TestBoundaryCases).

Some gaps remain, and they are recorded in a test that asserts the current, undesirable behaviour so nobody mistakes them for coverage:

Not detected Why it matters
empty fallback chain a decision with no provider at all passes
abstention route that names an unknown provider B1 checks presence, not that the destination exists
keep threshold equal to abstain threshold a zero-width band between answering and abstaining is probably a mistake
semantically overlapping answers with different words B3 compares text, not meaning, so “approve” and “accept” pass

The last row is the important one. B3 is a string comparison. Whether two options overlap in meaning is a semantic question, which is the kind a decision provider could answer. A spec validator that asks a provider whether two options overlap would be using a decision to check a decision. That is an interesting idea and it is untested.

The place on the Representation Ladder

The Language book names the ladder plainly: “There is a ladder of representations between ordinary language and executable machine state: prose, controlled prose, structured requirements, constraints, executable contracts, state-transition models, formal specifications and operational state.”

A DecisionSpec sits between structured requirements and constraints, rungs where expressiveness is still high and checkability is rising but the representation is not yet executable. The validator is what moves it toward executable: like Cedar’s validator, it makes the spec analysable before it is run. The book’s warning applies to it: “Making a statement easier to check can make it worse at preserving what was meant, so intent preservation, checkability and conformance must be kept apart.” The spec trades those. A tight schema can reject a spec whose meaning is subtle, and the chapter keeps the three separate rather than blaming a rejection on a meaning error.

Wrong / Correct. Wrong: “A decision specification is the executable program.” Correct: “A decision specification is a checkable representation of intent: Cedar’s validator for decisions. It sits between structured requirements and constraints on the ladder, it can catch bugs a library call cannot, and it is not, by itself, the program: the compiler (Chapter 33) is what makes it executable.”

What the result means

Authoring-time vs runtime. The spec and validator catch mistakes before anything runs. The library API catches mistakes at the moment of one call. Cedar argues the former. This chapter does not test that argument.

Specification vs provider vs program. The spec names the decision’s requirements; the provider answers; the program (Chapters 25-26, 34) composes. A spec that is forced to contain program facts (the provider registry, the handlers) is how the validator gains its power, and that is exactly why the API alone could not have the same checks.

Library form vs language form. PROPOSED, and an open question for Chapter 35. Everything in spec.py is a plain dataclass and one function. Nothing needs new syntax. If a Python library with a validate call does the same job, then “a decision specification” is a library result, and the language form earns its place only if it enables something the library cannot, such as checking across several decisions at compile time.

What to carry forward

Chapter 33 compiles the spec into a plan: compile(spec, profiles) -> plan, choosing among rule, classifier, retrieval, model, cascade and human from supplied cost and quality profiles. The validator hands it a guarantee of limited strength: the input plan’s declared intent is internally consistent, within the checked classes. The compiler’s job is the choice, not the meaning, but it inherits the validator’s blind spots.

Limitations

  • The validator is a hand-written rule set over five declared bug classes; it is not a general static-analysis system and will miss bugs outside the classes (see the gap table).
  • Seeded bugs were written by the validator’s author, one per class, in simple form. 5/5 is a property of those specs, not of all specs or of real authoring mistakes. No false-positive study beyond one clean spec.
  • Model Cards is cited only for its abstract. Cedar’s validator internals and evaluation were not studied for the rule set.
  • The Representation Ladder placement uses the Language book’s words, read in the source; no claim is made beyond that placement.
  • The B2, B3 and B5 definitions were tightened during review after boundary probing. The preregistered 5/5 result and results/ch32.jsonl are unchanged.
  • No model ran.

What this chapter establishes

What must a declarative decision specification say? The decision’s name, typed inputs and answers, its abstention route, its fallback chain, its required risk and thresholds, its evidence requirements. These are the fields the validator checks, and the ones Chapter 26’s graph records at run time.