← All @molecule/* packages · App templates
@molecule/api-ai-classification-llmProvider bond · ai-classification · API (Node) · v1.0.1 · Apache-2.0
LLM-backed classification provider for molecule.dev — composes the swappable ai chat bond to score text against candidate labels
npm install @molecule/api-ai-classification-llmnpm · Source on GitHub · Implements @molecule/api-ai-classification
@molecule/api-ai-classification-llm is a provider bond on the API (Node) side: it implements the ai-classification core interface (@molecule/api-ai-classification) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
import { bond } from '@molecule/api-bond'
import { provider as anthropic } from '@molecule/api-ai-anthropic'
import { provider as classification } from '@molecule/api-ai-classification-llm'
import { requireProvider } from '@molecule/api-ai-classification'
// Wire an AI provider + the classifier at startup.
bond('ai', anthropic)
bond('ai-classification', classification)
// Use it anywhere.
const result = await requireProvider().classify({
text: 'Win a FREE $1000 gift card now!!!',
labels: ['spam', 'ham'],
})
console.log(result.top) // 'spam'
console.log(result.labels) // [{ label: 'spam', score: 0.98 }, ...]Works with: @molecule/api-ai, @molecule/api-ai-classification, @molecule/api-i18n
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
LLM-backed zero-shot text classifier for molecule.dev — composes the
swappable ai chat bond to score candidate labels.
Prompts the bonded LLM to score the candidate labels as strict JSON, then
normalizes the result into a sorted, candidate-restricted ClassifyResult.
Because it resolves the ai provider lazily at call time, swapping the AI
provider automatically swaps the classifier's backing model.
import { bond } from '@molecule/api-bond'
import { provider as anthropic } from '@molecule/api-ai-anthropic'
import { provider as classification } from '@molecule/api-ai-classification-llm'
import { requireProvider } from '@molecule/api-ai-classification'
// Wire an AI provider + the classifier at startup.
bond('ai', anthropic)
bond('ai-classification', classification)
// Use it anywhere.
const result = await requireProvider().classify({
text: 'Win a FREE $1000 gift card now!!!',
labels: ['spam', 'ham'],
})
console.log(result.top) // 'spam'
console.log(result.labels) // [{ label: 'spam', score: 0.98 }, ...]
provider
npm install @molecule/api-ai-classification-llm @molecule/api-ai @molecule/api-ai-classification @molecule/api-i18n
providerLLM-backed AI classification provider (name: 'llm').
Zero-shot classifier composed over the swappable ai chat bond. Bond it via
bond('ai-classification', provider) and it will resolve the bonded ai
provider lazily at call time, so swapping the AI provider automatically
swaps the classifier's backing model.
const provider: AIClassificationProvider
Implements @molecule/api-ai-classification interface.
Setup function to register this provider with the core interface:
import { setProvider } from '@molecule/api-ai-classification'
import { provider } from '@molecule/api-ai-classification-llm'
export function setupAiClassificationLlm(): void {
setProvider(provider)
}
Peer dependencies:
@molecule/api-ai ^1.0.1@molecule/api-ai-classification ^1.0.1@molecule/api-i18n ^1.0.1@molecule/api-ai
@molecule/api-ai-classification
@molecule/api-i18n
Requires a bonded ai provider. classify() resolves the AI provider
from the bond registry at call time — bond one (bond('ai', anthropic))
before classifying, or pass provider: '<name>' to target a specific
named AI provider. It throws if none is bonded.
Swappable. Both the classifier (bond('ai-classification', ...)) and
the underlying model (bond('ai', ...)) are swappable at runtime.
Pass multiLabel: true when several labels can apply at once, and
instructions to give the model label definitions or extra guidance.
result.labels is restricted to the candidate set, sorted descending by
score; missing labels default to 0 and out-of-range scores are clamped
to 0..1. Unparseable model output THROWS (with an output snippet) rather
than returning silent garbage. Fenced json blocks and surrounding
prose are tolerated.
Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual screens/flows, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip:
top is one of the app's candidate labels, never free text,
with a score in 0..1. The sandbox has a live AI provider, so assert on
the actual result — never mock the classifier or hardcode a label.score and is routed to the app's "unsure"/unlabeled path rather than
silently assigned the top label.