Jev Case Study: Invoice Approval Gate (Fallback Code)
TL;DR: This Jev example builds an invoice approval gate on one judgment question: Jev 1.13 answers “approve under policy?” with
yes/no/unclearplus a confidence value, and the gate auto-approves only when the answer isyeswith confidence at 0.8 or higher. Everything else falls back to a human. Full Python below.
Scenario
Our accounts payable team processes a few thousand invoices a month. Most are unremarkable — under $500, matching a purchase order, correct vendor. A junior accountant still opened each one, checked three fields against the PO, and clicked approve: ten seconds of skilled attention per invoice, thousands of times a month.
The policy is simple enough to state in one sentence, so we turned it into one judgment question:
Should this invoice be auto-approved under policy (amount under $500, matching a purchase order)?
And one fallback rule, which is the actual point of this case study:
answer: "yes"andconfidence >= 0.8→ auto-approve, archive the rationale.answer: "no"→ reject and notify AP with the rationale.answer: "unclear"orconfidence < 0.8→ human review queue.
The gate never auto-approves on a whisper. A judgment model that says “yes, 0.55” is telling you the invoice sits in a gray zone — a missing PO reference, an unusual line item, a vendor name that almost matches. Those are exactly the invoices a person should see, and exactly why Jev — TypeSafe AI’s System One judgment model (September 2026) — returns confidence as a first-class field in its typed output rather than burying it in prose. Calls go through the OpenRouter OpenAI-compatible endpoint.
Request
{
"model": "typesafe/jev-1.13",
"messages": [
{
"role": "system",
"content": "Judgment question. Should this invoice be auto-approved under policy (amount under $500, matching a purchase order)? Answer yes, no, or unclear. Reply with JSON only: {\"answer\": <yes|no|unclear>, \"confidence\": <0-1>, \"rationale\": <one sentence>}"
},
{
"role": "user",
"content": "Invoice INV-2041 from Northwind Office Supply\nAmount: $412.80 | PO: PO-8877 | Terms: Net 30\nLine items: 12 ergonomic chair mats, matching PO-8877 pricing."
}
]
}
Response
Example fixture — illustrative output, not a live capture:
{
"answer": "yes",
"confidence": 0.97,
"rationale": "Amount is under $500, the invoice references PO-8877, and line items match the purchase order pricing."
}
The fixture is the boring case on purpose: clean yes, high confidence, auto-approved. The gate earns its keep on the cases where either field degrades — see the fallback table below.
Reproduce
Save as gate.py, set OPENROUTER_API_KEY, and run python3 gate.py:
import json, os, urllib.request
URL = "https://openrouter.ai/api/v1/chat/completions"
MODEL = "typesafe/jev-1.13" # confirm exact slug on the OpenRouter model page
HUMAN_REVIEW_CONFIDENCE = 0.8
SYSTEM = ('Judgment question. Should this invoice be auto-approved under '
'policy (amount under $500, matching a purchase order)? '
'Answer yes, no, or unclear. Reply with JSON only: '
'{"answer": <yes|no|unclear>, "confidence": <0-1>, "rationale": <one sentence>}')
def gate(invoice_text):
body = {"model": MODEL, "messages": [
{"role": "system", "content": SYSTEM},
{"role": "user", "content": invoice_text}]}
req = urllib.request.Request(URL, data=json.dumps(body).encode(),
headers={"Authorization": "Bearer " + os.environ["OPENROUTER_API_KEY"],
"Content-Type": "application/json"})
with urllib.request.urlopen(req) as res:
payload = json.load(res)
result = json.loads(payload["choices"][0]["message"]["content"])
if result["answer"] == "yes" and result["confidence"] >= HUMAN_REVIEW_CONFIDENCE:
return "auto-approved", result
return "human-review", result
invoice = """Invoice INV-2041 from Northwind Office Supply
Amount: $412.80 | PO: PO-8877 | Terms: Net 30
Line items: 12 ergonomic chair mats, matching PO-8877 pricing."""
print(gate(invoice))
Key parameters
| Field | Value | Why it matters |
|---|---|---|
model | typesafe/jev-1.13 | Pin the version — approval policy behavior must not drift silently. Confirm the exact slug on the OpenRouter model page. |
messages[0] (system) | Judgment question + full policy + JSON shape | The policy sentence is the approval rule. Any policy change means editing this one line. |
messages[1] (user) | The invoice fields | Send the structured fields AP already extracts; no need for the PDF. |
answer (response) | yes | Combined with confidence, decides the branch: approve / reject / review. |
confidence (response) | 0.97 (example fixture) | The fallback trigger: yes below 0.8 still goes to a human. |
rationale (response) | One sentence | Archived with the decision; it is the audit trail for every auto-approval. |
| Price | $0.0462 per 1M input tokens | One call per invoice; verify current pricing on OpenRouter before budgeting. |
Notes
- Responses are example fixtures; verify field names against official docs before relying on them. Official API details live at typesafe.ai — see the System One announcement post.
- Confirm the exact model slug (
typesafe/jev-1.13) on the OpenRouter model page before shipping. - Parse defensively in production: if
confidenceis missing or not a number, treat it as human-review, never as approval. - Log the confidence distribution weekly. A sudden shift toward low confidence usually means your invoice mix changed, not the model.
- Keep the policy sentence and your written AP policy in sync — the model only knows the rule you put in the system prompt.
- Applies to Jev 1.13 (released September 2026) via the OpenRouter demonstration channel.