qfa.services.coding_classifier#

Helpers for iterative LLM coding prompts and response parsing.

Functions

build_judge_messages(*, feedback_text, ...)

Build system and user messages for a single-level judge call.

build_pick_messages(*, feedback_text, ...[, ...])

Build the system and user messages for one hierarchy-level pick.

parse_selected_indices(raw, num_options)

Parse the model JSON response for one hierarchy-level pick.

Classes

JudgeResponse(*, score, explanation)

Structured output returned by the LLM judge for one hierarchy level.

class qfa.services.coding_classifier.JudgeResponse(*, score: float, explanation: str)[source]#

Bases: BaseModel

Structured output returned by the LLM judge for one hierarchy level.

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.

score: float#
explanation: str#
model_config = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

qfa.services.coding_classifier.build_pick_messages(*, feedback_text: str, current_level: str, labels: list[str], hierarchy_path: list[tuple[str, str]] | None = None) tuple[str, str][source]#

Build the system and user messages for one hierarchy-level pick.

qfa.services.coding_classifier.parse_selected_indices(raw: str, num_options: int) list[int][source]#

Parse the model JSON response for one hierarchy-level pick.

qfa.services.coding_classifier.build_judge_messages(*, feedback_text: str, level: str, path: list[tuple[str, str]]) tuple[str, str][source]#

Build system and user messages for a single-level judge call.

Parameters:
  • feedback_text – Raw text of the feedback record being coded.

  • level – The hierarchy level being evaluated: "Type", "Category", or "Code".

  • path – Full code path up to and including the current level, as [(level_name, label), ...]. E.g. for the Category judge: [("Type", "Service Delivery"), ("Category", "Staff Behavior")].