cadrumo.adapters.outbound.llm.text_classifier module

On-host TEXT evidence reader: classify/split from an extracted text layer.

Closes the capability gap that made the privacy posture inverted. Until this existed, a document’s transport was decided by an accident of how it was produced: a scan-only PDF was read on-host by a local vision model, while a PDF that happened to carry a text layer – the more machine-readable document – was the one whose contents left the machine to a cloud subprocess. The same taxpayer invoice took a different route depending on whether someone had scanned it or exported it.

This reader removes the fork’s cause rather than its symptom. Text-layer evidence now takes the same on-host path scanned evidence already took, over loopback HTTP to a local model, so no document class routes off-host and the gestor bar that applied to one arm of the fork and not the other disappears with it.

It is deliberately a sibling of LocalVisionLLMClassifier rather than a generalisation of it. The two differ only in transport – text in the prompt versus images on the message – and they share the prompt spec and the allow-list-guarded response parsing, which are the contracts that keep a model selecting only classification / category / iva_category and never emitting a regulated number. Merging them would fuse two payload shapes behind one branch for no gain.

class LocalTextLLMClassifier(*, spec, model=None, client=None, settings=None)[source]

Bases: object

Classify or split a transaction from extracted evidence text, on-host.

Parameters:
  • spec (PromptSpec) – Prompt spec carrying the registry-grounded category and IVA-category allow-lists – the same spec every other classifier uses, so the model’s answer space is identical whichever transport reads the document.

  • model (str | None) – Local Ollama text model identifier; defaults to Settings.cadrumo_llm_ollama_text_model.

  • client (LLMClient | None) – Injected LLMClient for tests; default-constructed against the resolved settings otherwise.

  • settings (Settings | None) – Injected settings; defaults to load_settings().

property decided_by: str

Provenance stamp recorded as classified_by.

Distinct from both the vision stamp and the retired cloud stamps, so a persisted record always says which on-host transport read it.

classify(transaction, *, evidence_text)[source]

Classify transaction, reading any extracted evidence text on-host.

Parameters:
  • transaction (Transaction) – The transaction to classify.

  • evidence_text (str | None) – Text extracted from the linked document, or None when the transaction carries no readable evidence.

Return type:

LLMClassificationResponse

Returns:

A validated, allow-list-guarded LLMClassificationResponse.

propose_split(transaction, *, evidence_text)[source]

Propose a split for transaction from its extracted evidence text.

Parameters:
  • transaction (Transaction) – The transaction to split.

  • evidence_text (str | None) – Text extracted from the linked document, or None.

Return type:

LLMSplitResponse

Returns:

A validated, allow-list-guarded LLMSplitResponse.