Classify entry via LLM sampling
classify_entryClassify a bank statement entry into a semantic category using LLM sampling, returning the chosen category, confidence score, and explanation.
Instructions
Classify one statement entry into a category via MCP LLM Sampling.
Use this when you want a semantic, model-driven label for an entry (payroll,
fee, refund, …) rather than a deterministic rule match. Because it delegates
an LLM completion to the client it is open-world and non-idempotent; for the
fixed candidate categories it chooses from, call
``list_classify_entry_categories`` first.
Uses the **MCP Sampling** protocol primitive: the server (this
process) asks the *client* (the agent's host application) to
perform an LLM completion on the server's behalf, then receives
the model's structured response. Keeps every LLM call in the
operator's existing model contract (privacy, billing, audit).
The model is asked to choose exactly one category from
``categories`` (or :data:`camt053_mcp.classify.DEFAULT_CATEGORIES`
if ``None`` is passed) and return a structured
``{category, confidence, explanation}`` payload.
Clients that do not support Sampling will get an
``{"error": "..."}`` envelope and can fall back to a rules-only
classifier.
Args:
ctx: The FastMCP Context (auto-injected; provides
``session.create_message``).
entry: A statement entry dict (the shape returned by
``parse_statement`` / ``list_entries``).
categories: The candidate categories. ``None`` uses the
built-in default list (12 common payment buckets).
Returns:
``{"category", "confidence", "explanation"}`` on success or
``{"error": "..."}`` on Sampling failure / malformed model
response / out-of-vocabulary category.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| entry | Yes | A single statement entry dict, in the shape returned by parse_statement / list_entries, to classify into one category. | |
| categories | No | The candidate categories the model must choose exactly one from. None (the default) uses the built-in default list exposed by list_classify_entry_categories. |