Lemonade Router Config Generator
Generate a
policy JSON from a plain-English description
of how requests should be routed. The skill produces and validates the JSON
only - it does not call the live server, register the policy, or run requests
through it. The JSON is accepted by the strict server-side parser on the first
try and stays editable in the desktop app's Hybrid Router editor.
Prerequisites
- Lemonade Server v10.1.0+ running locally ().
Required only to register and test the generated policy - the skill itself
(JSON generation + offline validation) works without a live server.
- No GPU or ROCm dependency for authoring. The router policy is a JSON
document; no hardware is needed to generate or validate it.
- Python (any 3.x) in PATH - used by the bundled offline validator
(). No extra packages required.
The router picks one candidate model per request. Two authoring modes
exist, and choosing the right one is the first decision:
| Mode | JSON shape | When |
|---|
| LLM-as-router | block | The user describes intent only by meaning ("sensitive", "hard questions", "creative writing") with no concrete signals. A small LLM reads each prompt and picks the candidate. |
| Rules | (+ optional ) | The user names any concrete signal: keywords, regex, length, tools, images, metadata, PII/topic classifiers, thresholds, "first match", fallback logic. Deterministic, no extra LLM call for simple conditions. |
is
mutually exclusive with
and
- never emit both.
Step 1 - Extract from the user's words
- Candidates: the models that may answer requests. Verbatim model names
(e.g. ). If the user names none, ask - never invent
model names. or shows what's available.
- Default / fallback: which candidate gets everything that matches nothing.
If unstated, use the model the user framed as "local", "small", or "safe";
otherwise the first candidate mentioned.
- Signals: every condition mentioned (keywords, patterns, length, images,
tools, topics, PII, safety) and which model each one routes to.
- Classifier models: models named for detection rather than answering
(BERT-style encoders, embedding models, an LLM used as judge).
Step 2 - Scaffold
Always exactly this envelope (the parser rejects unknown or missing keys):
json
{
"version": "1",
"model_name": "user.MyHybridRouter",
"recipe": "collection.router",
"components": [],
"routing": { }
}
- is the literal string .
- must start with ; slug from the user's description if
they gave a name ( using only ). If they didn't
name it, derive one from context instead of a fixed literal - e.g.
user.<slug-of-default-candidate>-Router
- so two different policies don't
collide by default. is idempotent per : registering a
second policy under the same name silently overwrites the first. If this
conversation already produced an unnamed router, don't reuse the same
derived name for the next one - ask, or pick a visibly different name.
Step 3 - Candidates and default
json
"candidates": ["<answering models>"],
"default_model": "<one of candidates>"
MUST be listed in
. Candidates should be
chat-capable LLMs - not embedding, classification, or image models.
Step 4 - Mode A: LLM-as-router
json
"router": {
"type": "llm",
"model": "<small chat LLM>",
"prompt": "You route user requests to the best model. <one sentence per candidate: when to pick it, using the exact model name>."
}
-
defaults to the smallest candidate (it may be a candidate; it also
works as a separate small model).
-
Write intent only - never specify a reply format and never use imperative
"Pick X" phrasing. The engine unconditionally appends its own contract
after your prompt: it lists the candidate names and demands a strict JSON
reply
{"model": "<name>", "rationale": "<one sentence>"}
, then falls back
to
on any deviation. A prompt that says "reply with ONLY the
model name", "Pick Model-A", "respond with the model name", or similar is
wrong about the wire format and causes weaker judge models to reply with a
bare string that fails to parse - silently falling back to
on every request with no visible error.
Bad (do not write):
"Pick Qwen3.5-9B-GGUF for sensitive queries, pick Qwen3.5-9B-NoThinking for everything else."
Good:
"Route to Qwen3.5-9B-GGUF when the request appears sensitive or contains personal information. Route to Qwen3.5-9B-NoThinking for all other requests."
Only describe when each candidate is appropriate. Never say "pick", "output", "reply with", or "respond with".
-
NEVER emit or in this mode. The
object
in Mode A must contain exactly:
,
, and
.
Adding
or
alongside
is a schema violation
that the server parser rejects. If you catch yourself writing both, stop and
remove
/
entirely.
Step 5 - Mode B: classifiers
Only declare classifiers the rules actually reference. Three types:
json
{ "id": "clf-1", "type": "classifier", "model": "<classification model>",
"labels": ["PII", "Jailbreak"], "default_label": "PII", "on_error": "match_false" }
{ "id": "clf-2", "type": "semantic_similarity", "model": "<embedding model>",
"reference_phrases": { "shopping": ["I want to shop for pants", "add to cart"] },
"default_label": "shopping", "on_error": "match_false" }
{ "id": "clf-3", "type": "llm", "model": "<chat LLM>",
"prompt": "Classify the request into only labels SAFE, RISKY",
"labels": ["SAFE", "RISKY"], "default_label": "SAFE", "on_error": "match_false" }
Hard constraints (parser-enforced - see
for the full matrix):
- type: model should be a text-classification model (an
encoder like ); must match the
model's actual output labels. A chat LLM here is legal (LLM-as-classifier
via chat) but prefer for that - it is explicit and prompted.
- : is ,
at least one concept, each with at least one phrase. Concept names ARE the
labels - a key is rejected for this type. Model must be an
embedding model. Give 3–5 varied phrases per concept when inventing them.
- : AND non-empty are both required. Write intent
only - never tell the model how to format its reply. The engine appends
its own
{"model": "<chosen_label>", "rationale": "..."}
contract after
your prompt (the same contract as ). An authored line like
"Reply with exactly one label: SAFE or RISKY" causes weaker models to output
bare , which the parser rejects - the score comes back empty and the
rule silently never fires. Describe what makes a request belong to each
label; leave the reply format to the engine.
- , when present, must be one of the labels/concepts.
- Defaults when unspecified: = , , …; =
(fail-open: a broken classifier doesn't match, so requests
fall through - use only when the user wants fail-closed
safety); = the first label.
Step 6 - Mode B: rules
json
"rules": [
{ "id": "rule-1", "match": { ... }, "route_to": "<candidate>",
"outputs": { "reason": "<optional free-form>" } }
]
- Order matters - first match wins. Put the most specific /
privacy-critical rules first (a "sensitive stays local" rule must precede a
"code goes to the big model" rule, or coding prompts with PII leak).
- MUST be a candidate. uses only ; default
, , ….
- No rule for the "everything else" case - that is .
Match conditions - combine with
(AND),
(OR),
; one
condition per leaf object; nesting is allowed:
| Leaf | Example | Notes |
|---|
| / | { "keywords_any": ["SSN", "Email"] }
| case-insensitive substring - matches inside , , , etc. Use with when word-boundary precision is needed |
| { "regex": "\\b\\d{3}-?\\d{2}-?\\d{4}\\b" }
| ECMAScript flavor |
| / | | input length, UTF-8 bytes, non-negative integer |
| / | | booleans |
| { "classifier": "clf-1", "label": "PII", "min_score": 0.5 }
| band test; / in [0,1]; default 0.5; omit only if the classifier has |
| { "metadata": { "key": "consent", "equals": "denied" } }
| exactly one of / / ; note: not editable in the desktop UI yet - use only when the user asks for metadata routing |
Step 7 - Components
= union of: all
+ every classifier
+ the
(Mode A). Deduplicate, keep order stable. The parser rejects
any referenced model that is not declared here.
Step 8 - Validate and output curl commands
These two actions are a single mandatory step. Do not stop between them.
8a. Run the offline validator before presenting anything to the user:
bash
python scripts/validate.py router.json # Windows
python3 scripts/validate.py router.json # macOS/Linux
It exits 0 with
when there are no errors. If it reports
errors, fix the JSON and re-run. Do not present a policy that fails this
check.
8b. Immediately after validation passes, print these three curl commands
as plain text for the user to copy and run. This is not optional. Fill in
and
from the policy, and a short
that should hit the first rule. Do not execute these with Bash or any tool —
print them as text only.
bash
# 1. Check a model exists before registering
curl http://localhost:13305/api/v1/models/<model-id>
# 2. Register the policy (idempotent - re-POST to update)
curl -X POST http://localhost:13305/api/v1/pull \
-H "Content-Type: application/json" --data-binary @router.json
# 3. Route a request and inspect the decision
curl -X POST http://localhost:13305/api/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "<model_name>", "route_trace": true,
"messages": [{"role": "user", "content": "<test prompt>"}]}'
The
response header carries the matched rule id (or
). With
the body also carries
:
{ route_to, matched_rule, default_used, outputs, trace[] }
- useful for verifying each rule fires as expected.
Defaults summary
| Field | Default when the user doesn't say |
|---|
| user.<default-candidate-slug>-Router
(never reuse a name already used earlier in this conversation) |
| the "small/local/safe" candidate, else first mentioned |
| mode | rules if any concrete signal is named, else LLM-as-router |
| classifier / rule | / |
| |
| first label / concept |
| |
| omit |
| router prompt | intent only - no reply-format instruction (Step 4) |
Worked NL → JSON pairs live in
; the full schema, parser error
matrix, and model-capability table live in
; the offline
validator is
(run it - see Step 8).