Skip to navigation

Custom classifiers

Train Gateway on your own definition of a simple versus complex request

A custom classifier teaches Gateway what “simple” and “complex” mean for your workload, from prompts you label, and replaces the built-in complexity scorer in a Build Your Own Router config. Use one when the built-in signal misreads your traffic, such as a one-line support message that is really a hard reconciliation task.

How it works

You supply {prompt, complexity} examples, 0 (trivial) to 1 (complex). Gateway splits them at 0.5, embeds every prompt, and averages each side into a centroid, with no eval run or judge model. Each request is embedded and scored by how much closer it sits to the complex centroid than the simple one.

The classifier scores complexity only, which BYOR uses to tilt model scores. Per-model scores come from your benchmarks, and categories such as code or math from BYOR’s capability classifier.

Prepare training data

Score prompts by difficulty for your workload, not length. You need at least 3 examples below 0.5 and 3 at 0.5 or above; more per side gives a steadier score.

training-data.json
[
{"prompt": "Reconcile these two conflicting invoices for customer_abc and explain every discrepancy", "complexity": 0.9},
{"prompt": "A customer's OAuth token refresh fails intermittently across three regions, trace the root cause", "complexity": 0.95},
{"prompt": "Draft a migration plan to move our webhook consumers off the deprecated v1 endpoint", "complexity": 0.85},
{"prompt": "Change the billing email on account customer_abc", "complexity": 0.15},
{"prompt": "Reset the password for alice@acme.com", "complexity": 0.1},
{"prompt": "What are your support hours?", "complexity": 0.05}
]

prompt must be a non-empty string and complexity a number from 0 to 1; errors name the 1-based item number. For a spreadsheet, choose Import from CSV: one example per row, score in the last column. A header row is skipped, and commas inside the prompt are kept.

Create a classifier

  1. In Routing policies → Prompt classifiers, select Add classifier
  2. Enter a name (unique in your organization) and optional description
  3. Paste the JSON into Scored prompts (JSON), or import a CSV
  4. Select Add classifier. The button stays disabled until each side has 3 examples

Creating or editing needs Manage routing; viewing needs View routing.

Use it in a BYOR config

In the BYOR config editor under Routing policies → Policies, pick your classifier in Classifier and save, or leave Default for the built-in scorer. A classifier edited below 3 examples per side has no scorer and disappears from the selector. Intelligent policies can’t use classifiers.

Improve it with routing feedback

Rate how real requests were routed, and Gateway adds them to your classifier as labeled examples. Use this to correct the classifier from live traffic instead of writing new examples by hand.

In Logs, open a request your classifier scored and select thumbs up (routing was right) or thumbs down (routing was wrong). The console shows whether the rating trained the classifier, or why not.

From code, send the request’s id, from the x-request-id response header, with a management key:

cURL
curl -X POST https://api-gateway.merge.dev/v1/classifiers/feedback \
-H "Authorization: Bearer $MERGE_GATEWAY_MANAGEMENT_KEY" \
-H "Content-Type: application/json" \
-d '{
"request_id": "3f9c2b1a-6d7e-4f80-9a1b-2c3d4e5f6a7b",
"verdict": "bad",
"direction": "stronger",
"prompt": "Reconcile these two conflicting invoices for customer_abc and explain every discrepancy"
}'
FieldValue
verdictgood or bad
directionFor bad: stronger or cheaper, the way routing should have gone. Optional when the request already went to the cheapest or strongest tier.
correct_complexityOptional: the score it should have had, 0 to 1
promptThe request’s last user message. Without it, the feedback is stored but doesn’t train.

The response’s trained says whether an example was added, and skip_reason says why not. The classifier rebuilds within 10 minutes. Only the first feedback on a request trains, and a classifier keeps up to 500 feedback examples.

A thumbs rating in Logs sends the prompt from the logged request body, so it trains only when request bodies are logged for that request

Edit or delete

Editing examples rebuilds the classifier, and configs using it pick up the change on the next request. Deleting it detaches it, and those configs fall back to the built-in scorer instead of failing.

Next steps