ractogateway.pipelines.list_classifier._models
Data models for ListClassifierPipeline.
- exception ractogateway.pipelines.list_classifier._models.ClassifierRateLimitExceededError[source]
Bases:
RuntimeErrorRaised when the rate limiter denies a request for a given user.
- class ractogateway.pipelines.list_classifier._models.ClassifierUsage(**data)[source]
Bases:
BaseModelToken usage and retry statistics for a single pipeline call.
Properties
- total_tokens:
Sum of input_tokens and output_tokens across all LLM attempts, including automatic retries triggered by invalid LLM responses. Zero on a cache hit (no LLM call was made).
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- input_tokens: int
- output_tokens: int
- retry_count: int
- property total_tokens: int
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class ractogateway.pipelines.list_classifier._models.AuditEntry(**data)[source]
Bases:
BaseModelImmutable audit record emitted to the
audit_loggerafter every call.Emitted regardless of whether the call was served from cache, hit an error, or was a live LLM classification. Provides a complete picture of every request for compliance, debugging, and analytics.
Fields
- timestamp:
ISO 8601 UTC timestamp of when the call was made (e.g.
"2026-02-26T14:23:01.456789Z").- user_query:
Original natural-language query.
- options_provided:
Full candidate list shown to the LLM (including
uncertain_labelif one was configured).- selected:
Option(s) chosen by the LLM, or empty on error.
- confidences:
Per-selection confidence scores, or
None.- all_scores:
Score for every option (when
score_all=True), orNone.- reasoning:
LLM explanation (when
include_reasoning=True), orNone.- fuzzy_corrected:
Truewhen the LLM returned a near-miss that was fuzzy-matched.- uncertain:
Truewhen the LLM selected theuncertain_labeloption.- cache_hit:
"exact"or"semantic"when the result was served from cache;Nonewhen a live LLM call was made.- user_id:
User identifier passed to the pipeline (for rate limiting / audit).
- session_id:
Conversation session identifier (for memory context).
- latency_ms:
Wall-clock latency of the entire pipeline call in milliseconds (near-zero for cache hits).
- usage:
Token usage dict — keys:
input_tokens,output_tokens,total_tokens,retry_count. All zero on cache hits.- error:
Non-
Nonewhensafe_mode=Trueand an exception occurred.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- timestamp: str
- user_query: str
- fuzzy_corrected: bool
- uncertain: bool
- latency_ms: float
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class ractogateway.pipelines.list_classifier._models.ClassifierResult(**data)[source]
Bases:
BaseModelResult returned by
ListClassifierPipeline.All fields except
user_queryandoptions_providedhave sensible defaults so that a partial result can be returned whensafe_mode=Trueand an error occurs mid-pipeline.Fields
- user_query:
The original natural-language query passed to the pipeline.
- options_provided:
The full list of candidate strings presented to the LLM (including the injected
uncertain_labeloption if one was configured).- selected:
The option(s) chosen by the LLM, ordered by descending confidence. Empty when an error occurred and
safe_mode=True.- confidences:
Per-selection confidence scores in [0.0, 1.0], aligned with
selected.Nonewheninclude_confidence=False.- all_scores:
Confidence score for every option in the list, keyed by option string.
Nonewhenscore_all=False(the default).- reasoning:
Brief natural-language explanation produced by the LLM.
Nonewheninclude_reasoning=False.- fuzzy_corrected:
Truewhen the LLM returned a near-miss that was corrected by the built-in fuzzy matcher without consuming a retry.- uncertain:
Truewhen the LLM selected theuncertain_labeloption, indicating no real option matched the query well enough.- cache_hit:
"exact"or"semantic"when served from cache;Nonefor a live LLM call.- usage:
Aggregated token counts and retry statistics for this call.
- error:
Non-
Noneonly whensafe_mode=Trueand an exception occurred. Whenerroris set,selectedwill be empty.
Examples
>>> result.first # "Billing" >>> result.top_confidence # 0.95 >>> result.as_string() # "Billing, Account" >>> result.as_dict() # {"selected": ["Billing"], ...} >>> result.as_enum()["Billing"].value # "Billing" >>> result.uncertain # False >>> result.cache_hit # "exact" | "semantic" | None
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- user_query: str
- fuzzy_corrected: bool
- uncertain: bool
- usage: ClassifierUsage
- property is_empty: bool
Truewhen no options were selected (including error cases).
- as_string(separator=', ')[source]
Return selected options as a single joined string.
- as_dict()[source]
Return a plain
dictwith selected options and optional metadata.Always contains
"selected"."confidences","all_scores", and"reasoning"are included only when they are non-None.
- as_enum(name='SelectedOptions')[source]
Return a dynamic Python
enum.Enumof the selected options.- Parameters:
name (
str) – Class name for the generated Enum. Default:"SelectedOptions".- Return type:
- Returns:
type[Enum] – An Enum whose members have the option string as both name and value.
Example
>>> E = result.as_enum() >>> E["Billing"].value # "Billing"
- top_n(n)[source]
Return the top-n selected options.
- score_for(option)[source]
Return the confidence score for a specific option, or
None.Searches
all_scoresfirst (all options, whenscore_all=True), thenconfidencesfor selected items.
- to_audit_entry(*, timestamp, user_id=None, session_id=None, latency_ms=0.0)[source]
Build an
AuditEntryfrom this result.Called automatically by the pipeline — exposed here so that users can reconstruct audit entries from stored results if needed.
- Return type:
AuditEntry
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].