LLM Classification
Turn any LLM into a reliable classifier with structured prompts, schema-enforced outputs, and graceful fallback. This recipe shows how to route customer messages, tag tickets, and score sentiment using Meridian's gateway in under twenty lines of code.
1Pick a small, fast model
Classification tasks rarely need a frontier model. Start with a 4o-mini or Haiku tier through azure/model-routerand let Meridian fall back automatically if the route stalls. Cheap models hit 95%+ accuracy on well-bounded label sets.
2Constrain the output schema
Force the model to emit JSON that matches a fixed enum. This eliminates free-form drift and lets you parse the response with confidence. Always include anunknown label as an escape hatch so the model never has to guess.
const labels = ["billing", "technical", "feedback", "unknown"];
const response = await fetch("https://llm.getnimbus.net/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer " + process.env.MERIDIAN_KEY,
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "azure/model-router",
messages: [
{ role: "system", content: "Reply with one word: " + labels.join(", ") },
{ role: "user", content: ticket.text }
],
max_tokens: 8
})
});
const json = await response.json();
const label = json.choices[0].message.content.trim().toLowerCase();
const valid = labels.includes(label) ? label : "unknown";3Add confidence and review
For high-stakes routing, ask the model to emit a confidence score alongside the label and queue anything below 0.7 for human review. Log every classification with its input hash so you can replay misroutes and tune the system prompt over time.