Build AI systems without hardcoded model choices.
Send a policy with each request. unhardcoded filters the live model catalog, picks the cheapest model that satisfies your rules, runs it through your provider keys, and returns a trace of the decision.
fp 301140696-1054914287
The model routing loop
One policy decides one call. Same inputs, same catalog, same decision. Every time, and written down.
top_k failover cascade.Workflow patterns
A workflow is a bounded, acyclic graph of routed steps. Each node carries its own policy and routes independently; the whole graph writes one stitched trace. This is where unhardcoded stops being "routing with rules" and becomes a system.
Triage cheap, draft to a quality floor, then a strong no-log guard that can refuse before anything ships.
Why it matters: the last step is a policy-enforced gate that can abort the send, not a hoped-for check.
View flow_ir
["flow", {
"u": {"kind": "input"},
"t": {"kind": "llm", "system": "Classify the ticket and extract the account id as JSON.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["has_cap", "supports_json_mode"]],
["neg", ["normalize", ["field", "price_out"]]], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["u"]},
"d": {"kind": "llm", "system": "Write a reply using the ticket and the triage.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["cmp", "bench_intelligence", "ge", 0.55]],
["neg", ["normalize", ["field", "price_out"]]], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["u", "t"], "template": "Ticket:\n$1\n\nTriage:\n$2"},
"g": {"kind": "llm", "system": "Check brand voice, PII, refund limits. Refuse if any fail.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["is", "no_log"]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["d"]},
"out": {"kind": "output", "inputs": ["g"]}
}]A cheap first draft, a strong critic that lists the flaws, then a rewrite that fixes every point.
Why it matters: a quality jump on a budget: most of the tokens run on the cheap model.
View flow_ir
["flow", {
"u": {"kind": "input"},
"d": {"kind": "llm", "system": "Draft an answer.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["neg", ["normalize", ["field", "price_out"]]], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["u"]},
"c": {"kind": "llm", "system": "Critique the draft: list concrete flaws and gaps.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["d"]},
"r": {"kind": "llm", "system": "Rewrite the answer, fixing every point in the critique.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["u", "d", "c"], "template": "Question:\n$1\n\nDraft:\n$2\n\nCritique:\n$3"},
"out": {"kind": "output", "inputs": ["r"]}
}]N seeded draws from the same strong policy, then a judge picks the single best.
Why it matters: sample spreads the draws across the top of the ranking deterministically: reproducible diversity, not luck.
View flow_ir
["flow", {
"u": {"kind": "input"},
"n1": {"kind": "llm", "system": "Answer the question.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["sample", 0.5], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["u"]},
// n2, n3: the same policy, two more seeded draws
"j": {"kind": "llm", "system": "Pick the single best candidate; return it verbatim.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["n1", "n2", "n3"], "template": "A:\n$1\n\nB:\n$2\n\nC:\n$3"},
"out": {"kind": "output", "inputs": ["j"]}
}]Three models pinned by family draft in parallel; a fourth synthesizes the best single answer.
Why it matters: family_eq pins an exact model line, so a panel is reproducible, not "whatever was cheapest today."
View flow_ir
["flow", {
"u": {"kind": "input"},
"a": {"kind": "llm", "system": "Draft an answer.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["family_eq", "gemini-3.1-pro-preview"]],
["zero"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]], "inputs": ["u"]},
// b: family_eq "claude-opus-4-8" · c: family_eq "deepseek-v4-flash"
"f": {"kind": "llm", "system": "Synthesize the single best answer from the drafts.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["a", "b", "c"]},
"out": {"kind": "output", "inputs": ["f"]}
}]A reasoner and a coder run in parallel under different filters, then a merge step fuses them.
Why it matters: each branch picks the best model for its job (reasoning vs coding) instead of one model doing everything.
View flow_ir
["flow", {
"u": {"kind": "input"},
"rz": {"kind": "llm", "system": "Reason through the problem step by step.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["is", "cap_reasoning"]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]], "inputs": ["u"]},
"cd": {"kind": "llm", "system": "Produce any code the problem needs.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["cmp", "bench_coding_rank", "le", 5]],
["field", "bench_coding"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]], "inputs": ["u"]},
"m": {"kind": "llm", "system": "Merge the reasoning and the code into one answer.",
"policy": ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"], ["argmax"], ["id"], ["always", {"action": "next_candidate"}]],
"inputs": ["rz", "cd"], "template": "Reasoning:\n$1\n\nCode:\n$2"},
"out": {"kind": "output", "inputs": ["m"]}
}]The full workflow guide: node kinds, graph limits, templates →
Quickstart
unhardcoded is OpenAI-compatible. Three changes from a normal call.
-
Point your SDK at the host.Change the
baseURL; everything else in the SDK stays the same.const client = new OpenAI({ baseURL: "https://<your-host>/v1", apiKey: process.env.UNHARDCODED_KEY, }); -
Attach a policy to the call.Build a
policy_irin your backend and send it alongsidemessages. Routing comes from the policy, somodelis just a trace label.const res = await client.chat.completions.create({ model: "policy:support", policy_ir: ["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["cmp", "bench_intelligence", "ge", 0.5]], // filter ["neg", ["normalize", ["field", "price_out"]]], // rank: cheapest ["argmax"], ["id"], ["always", {"action": "next_candidate"}]], messages, }); -
Read the trace.The response carries the decision: the chosen model, the candidates it ranked and rejected, and the policy fingerprint.
{ "chosen": { "model_family": "deepseek-v4-pro", "price_out": 1.5 }, "trace": { "policy_fingerprint": "301140696-1054914287", "rejected": [{ "model_family": "deepseek-v4-flash", "reason": "cmp bench_intelligence ge 0.5" }], "total_latency_ms": 425 } }
Policy presets
Common routing patterns as cards. Read the rules, copy the policy, adjust the floor and ceiling.
bench_intelligence ge 0.5price_outView JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]],
["cmp", "bench_intelligence", "ge", 0.5]],
["neg", ["normalize", ["field", "price_out"]]],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]View JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["add",
["scale", 0.6, ["normalize", ["field", "bench_intelligence"]]],
["scale", 0.4, ["neg", ["normalize", ["field", "price_out"]]]]],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]bench_intelligenceView JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]]],
["field", "bench_intelligence"],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]is cap_reasoningView JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["is", "cap_reasoning"]],
["field", "bench_intelligence"],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]is in_imageprice_outView JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["is", "in_image"]],
["neg", ["normalize", ["field", "price_out"]]],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]context ge 200000price_outView JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]], ["cmp", "context", "ge", 200000]],
["neg", ["normalize", ["field", "price_out"]]],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]bench_agentic_rank le 5bench_agenticView JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]],
["has_cap", "supports_tools"], ["cmp", "bench_agentic_rank", "le", 5]],
["field", "bench_agentic"],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]is has_tee · is no_logView JSON
["policy", ["and", ["meets_req"], ["not", ["is", "disabled"]],
["is", "has_tee"], ["is", "no_log"]],
["field", "bench_intelligence"],
["argmax"], ["id"], ["always", {"action": "next_candidate"}]]Every decision leaves a receipt
A trace is a structured, replayable record of how the model was chosen: which models were considered, why each passed or failed, what ran, and how to reproduce it.
sha256. A workflow also carries a flow_fingerprint.Reference
The complete spec, kept out of the reading path.
Source on GitHub: unhardcoded (the host) · unhardcoded-engine (the policy engine)