Routing

Escalate uncertain classifications

Separate a predicted label from the decision to act on it.

ChoiceAdapted exampleSource reviewedNot live-tested

01 The question

request choice

What action is the customer asking for? Choose unclear if the message does not establish a specific action.

cancel
Explicitly end the subscription.
change_plan
Switch to a different subscription plan.
billing_date
Change when a payment is collected.
unclear
The requested action cannot be determined from this message.

Copy includes the complete instructions, criteria, usage notes, and attribution.

02 Input

A request that may be clear enough to classify or may need a follow-up.

Illustrative input · JSON
{
  "message": "Can I move this to next month? I’m not sure which plan I’m on."
}

03 Answer & policy

A selected request type and confidence, plus the option probabilities.

Your code decides what happens next.

Route unclear labels and confidence below 0.8 to clarification. The threshold illustrates the mechanism; validate it for your own traffic. The example does not perform account changes.

04 Use it in your code

Node.js 24 · TypeSafe SDK 0.6.0 · Set TYPESAFE_API_KEY in your environment. Run on your server; API calls incur provider charges.

decision.ts · TypeScript
import { choice, TypeSafeClient, type JsonValue } from "@typesafe-ai/sdk";

// Illustrative input, not a recorded model test.
const state: JsonValue = {
  "message": "Can I move this to next month? I’m not sure which plan I’m on."
};
const client = new TypeSafeClient();
try {
  const response = await client.systemOne({
    model: "jev-latest",
    state,
    questions: {
      request: choice(
        "What action is the customer asking for? Choose unclear if the message does not establish a specific action.",
        {
          "cancel": "Explicitly end the subscription.",
          "change_plan": "Switch to a different subscription plan.",
          "billing_date": "Change when a payment is collected.",
          "unclear": "The requested action cannot be determined from this message."
        }
      )
    },
  });

  const answer = response.answers.request;
  console.log({
    next: answer.choice === "unclear" || answer.confidence < 0.8
      ? "ask_for_clarification" : "review_requested_action",
    request: answer.choice,
  });
} catch (error) {
  console.error("Decision unavailable; use your fallback or human review.", error);
  process.exitCode = 1;
}
Download .ts ↓SDK setup ↗Copy and download include license notices.

The wrapper and example input are provided by Jev Directory. Checked against SDK types; no live model call was made. Pin a model version before evaluating production behavior.

Before you adapt it

  • A confident wrong answer can still pass the gate.
  • Do not confuse the chosen label’s probability with the separate confidence field.
More about the original project or pattern

What it does

Confidence-gated routing treats a model answer and its confidence as separate inputs to application policy. The answer identifies a proposed action; confidence controls whether software proceeds, asks for confirmation, sends the item to a person, or declines to act.

What you can reuse

The reusable part is the risk-sensitive gate. Low-stakes actions can tolerate a lower threshold, while consequential actions require more confidence or an extra confirmation step. A common floor can catch broadly uncertain cases before action-specific rules apply.

How it fits

Jev provides a typed answer and confidence. Deterministic code compares that result with thresholds selected for the action’s consequences. The fallback behavior remains visible in code and can differ by route.

Setup and compatibility

The official example uses a voice-banking Choice question to illustrate the pattern. Use its structure as a starting point and derive thresholds from representative data for the actual domain.

Limitations

The numerical thresholds in the source are illustrative. Confidence is not proof of correctness, and one threshold should not be carried into a different question or risk context without evaluation. High-impact automation may need confirmation, human review, or a hard prohibition regardless of model confidence.

Sources

Primary source: TypeSafe confidence-gated routing.