soev for developers
soev-evalsReference

soev_evals.core

Pure evaluation models, ports, loading and scoring.

A project file names the system under test and its suites. A suite file holds cases. A case holds the turns of a conversation and the criteria that grade the reply. A run starts a conversation for each attempt of a case through an arm, and collects the evidence. Then each criterion gives a verdict on the evidence. soev_evals.core does no I/O of its own: it gets the YAML text and the services from its caller.

Cases and suites

A suite is a list of cases with the criteria that they share. Load it from YAML text.

Suite

modelSuite

Cases and shared criteria from one logical suite.

A suite can span several YAML files: load_suites merges them. Validation fails when two cases have the same id, when a case names another suite, or when a case does not match id_pattern.

attributenamestr

The name of the suite. The project names its suites by this name.

attributeid_patternstr | None
= None

A regular expression with one capture group, or None. Each case id must match it in full, and the group must equal the case's rule.

attributedefaultslist[CriterionSpec]
= list()

The criteria of every case of the suite. They come before the criteria of each case.

attributecaseslist[Case]

The cases. A suite has at least one case.

methodcriteria_for(case) -> list[CriterionSpec]

Return suite defaults followed by case-specific criteria.

A run adds the project invariants before this list.

paramcaseCase

A case of this suite.

Returns

list[CriterionSpec]

The criteria that grade each attempt of case, in order.

load_suite

functionload_suite(text, registry) -> Suite

Load one suite from YAML text. The function reads no file.

The registry checks the kind and the parameters of each criterion, so an unknown kind or a wrong parameter fails here, before a run starts.

Example

from soev_evals.core import load_suite
from soev_evals.criteria import builtin_registry

text = '''
name: smoke
cases:
  - id: greet
    lineage: greet
    category: smalltalk
    turns:
      - prompt: Hallo, wie ben jij?
    criteria:
      - kind: reply.language
        language: nl
'''
suite = load_suite(text, builtin_registry())
paramtextstr

The YAML text of one suite file.

paramregistryCriterionRegistry

The criterion kinds that the suite can use.

Returns

Suite

The validated suite.

Raises:

  • SuiteError: The text is not valid YAML or not a valid suite, or a criterion has an unknown kind or invalid parameters.

load_suites

functionload_suites(documents, registry) -> Suite

Merge the files of one suite into one suite.

The merged suite has the cases of all documents, in the order of documents.

paramdocumentsSequence[str]

The YAML text of each file of the suite.

paramregistryCriterionRegistry

The criterion kinds that the suite can use.

Returns

Suite

One suite with the cases of all documents.

Raises:

  • SuiteError: documents is empty, a document is not a valid suite, the documents differ in name, defaults or id_pattern, or two documents have a case with the same id.

Case

modelCase

A conversation and its project-independent evaluation definition.

A case is one entry of a suite file. Each attempt of a case runs its turns on a new conversation, and each variant on a new conversation of its own. Then the criteria grade the evidence.

attributeidstr

The id of the case. It is unique in its suite and in the project.

attributesuitestr

The name of the suite. A suite file fills it in when the case leaves it out.

attributestatusLiteral['active', 'draft', 'retired']
= 'active'

Only "active" cases run. "draft" and "retired" cases stay in the file.

attributesplitLiteral['dev', 'test'] | None
= None

The side of the dataset, "dev" or "test", or None before a split. The seal covers the test cases.

attributelineagestr

The group of the case and the cases derived from it. A split puts a whole lineage on one side.

attributecategorystr

A free label. The report gives scores for each category.

attributerulestr | None
= None

The id of the rule that the case tests, or None. The report gives scores for each rule, and Suite.id_pattern checks it against the case id.

attributederived_fromstr | None
= None

The id of the case that this case derives from, or None for the root of a lineage.

attributeprovenanceProvenance
= Provenance()

The generation and review history.

attributeturnslist[Turn]

The user prompts, in order. A case has at least one turn.

attributevariantsdict[str, list[Turn]]
= dict()

Other versions of the turns, by name. The compare.* criteria compare their evidence with the evidence of turns.

attributeexpectExpect
= Expect()

What the system must do and say.

attributeanswerabilityAnswerability | None
= None

An assessment of how well the sources cover the question, or None.

attributecriterialist[CriterionSpec]
= list()

The criteria of this case. They come after the suite defaults.

attributesetupdict[str, JsonValue]
= dict()

Free data for the project's CaseSetup, which receives the whole case.

Turn

modelTurn

One user prompt in a conversation.

attributepromptstr

The text that the arm sends as the user input. It is nonempty.

Expect

modelExpect

The expected behaviour, content and source roles for a case.

attributebehaviourLiteral['answer', 'refuse', 'abstain']
= 'answer'

What the system must do: "answer", "refuse" or "abstain". behaviour.expected asks the judge for this label.

attributemessagestr | None
= None

The key of a message in Project.messages. behaviour.message requires its text in the reply, and refusal.code expects this code for a refusal or an abstention.

attributeanswerstr | None
= None

A reference answer, or None. rubric.judge gives it to the judge.

attributenuggetslist[Nugget]
= list()

The facts that the reply must cover.

attributesourcesSourceRoles
= SourceRoles()

The roles of the sources that the reply can cite.

Nugget

modelNugget

A reference fact and the ids of the sources that support it.

The nuggets.coverage criterion asks the judge whether the reply covers each nugget.

attributetextstr

The fact. It is nonempty.

attributeimportanceLiteral['vital', 'okay']
= 'vital'

"vital" or "okay". The coverage score counts only the vital nuggets.

attributesourceslist[str]
= list()

The ids of the sources that support the fact. The judge receives them with the fact.

SourceRoles

modelSourceRoles

Required alternative groups, supporting sources and forbidden sources.

Each entry is a source id, as CitationMapping resolves it from a citation. The citation criteria compare these ids with the cited ids. With the default match "hierarchical", an id also matches the ids below it in the / path: law/1 matches law/1/2, and law/1/2 matches law/1.

attributerequireddict[str, list[str]]
= dict()

Groups of alternative sources, by group name. A citation of one member covers its group. citations.required scores the share of covered groups.

attributesupportinglist[str]
= list()

Sources that a reply can cite. citations.unseen does not list them.

attributeforbiddenlist[str]
= list()

Sources that a reply must not cite. citations.forbidden fails on each such citation.

Provenance

modelProvenance

Generation and review history carried with a case.

This package stores the history with the case, but does not read it.

attributegeneratorstr | None
= None

Who or what wrote the case, or None when unknown.

attributereviewerstr | None
= None

Who reviewed the case, or None when nobody did.

attributeroundint | None
= None

The number of the review round, from 0, or None.

attributenotesJsonValue
= None

Free JSON notes.

Answerability

modelAnswerability

Source coverage assessment and non-authoritative hints for expert review.

This package stores and validates the assessment, but no built-in criterion reads it.

attributelabelAnswerabilityLabel

How well the sources cover the question.

attributelimitationslist[Limitation]
= list()

Why the coverage is limited. It is nonempty exactly when label is "limited".

attributesource_hintslist[str]
= list()

Ids of sources that can help a reviewer. Each id is nonempty.

attributedetailstr
= ''

A free explanation of the assessment.

attributeassessed_byLiteral['judge', 'expert']

Who made the assessment: "judge" or "expert".

AnswerabilityLabel

type aliasAnswerabilityLabel = Literal['full', 'limited', 'not_regulated', 'unanswerable']

The label of an Answerability assessment: how well the sources cover the question of a case.

Only the label "limited" has reasons, as a list of Limitation values.

Limitation

type aliasLimitation = Literal['lower_regulation', 'parliamentary_history', 'case_law_or_guidance', 'fact_dependent']

A reason for the Answerability label "limited".

SuiteError

errorSuiteError

Suite content is invalid or inconsistent.

load_suite and load_suites raise it.

Projects

A project holds the system under test, the judge settings, the suites and the criteria that every case shares.

Project

modelProject

Project-owned arm, judge, suites, hooks and invariant definitions.

A project is one YAML file. It names the system under test, the suites and the criteria that every case shares. load of soev_evals.cli reads it with its suites, its hooks and its corpus lookup.

attributenamestr

The name of the project.

attributelanguagestr

The main language of the project, as a language code.

attributesystemSystemConfig

The system under test.

attributejudgeJudgeConfig

The judge settings.

attributerunsRunsConfig
= RunsConfig()

The number of attempts of each case.

attributeconcurrencyint
= 1

The number of attempts that run at the same time, at least 1.

attributeinvariantslist[CriterionSpec]
= list()

The criteria of every case of every suite. They come before the suite defaults.

attributemessagesdict[str, str]
= dict()

The fixed messages of the system, by key. Expect.message names a key.

attributecitationsCitationMapping

How the arm finds the source id of a cited element.

attributehooksstr | None
= None

The name of a Python module to import, or None. Its attribute CRITERIA lists more criterion kinds, and its attribute SETUP is the CaseSetup of the project.

attributesplitSplitConfig
= SplitConfig()

The settings of a dataset split.

attributesuitesdict[str, str]
= dict()

The glob pattern of the files of each suite, by suite name, relative to the folder of the project file.

attributeruntimestr | None
= None

The name of the runtime provider in the entry point group soev.evals.runtimes, or None for the HTTP arm. The --runtime option replaces it.

attributecorpusCorpusLookupConfig
= CorpusLookupConfig()

Where the corpus lookup file is.

attributeextensionsdict[str, JsonValue]
= dict()

Free JSON settings for other tools. This package does not read them.

SystemConfig

modelSystemConfig

The settings of the arm: the server, the agent and the names of the environment variables of its credentials.

The project file holds only the names of the environment variables, never their values. The arm reads the values when it opens its HTTP client.

attributearmLiteral['soev_thread']
= 'soev_thread'

The kind of arm. "soev_thread" is the only kind: the threads API of a soev server.

attributeurl_envstr

The environment variable with the base URL of the server.

attributecredential_envstr

The environment variable with the bearer token for the server.

attributesubject_envstr

The environment variable with the subject that the arm sends in the X-Soev-Subject header.

attributeagentstr

The name of the agent that each new thread runs.

attributemodelstr | None
= None

The model that each input asks for, or None for the default model of the agent.

attributeknowledgelist[str]
= list()

The knowledge keys that each input sends.

attributetimeout_sfloat
= 120.0

The timeout of each HTTP request, in seconds.

JudgeConfig

modelJudgeConfig

The judge settings of a project.

soev_evals records endpoint in the manifest, but connects no judge to it. A RuntimeProvider reads it to make its judge.

attributeendpointstr

The name of the judge endpoint. The run manifest records it.

attributecontextLiteral['units', 'corpus']
= 'units'

The source context of the judge: "units" or "corpus". This package does not read it.

RunsConfig

modelRunsConfig

The requested repetition count for each case.

attributekint
= 1

The number of attempts of each case in a run, at least 1. The --k option of run replaces it.

CitationMapping

modelCitationMapping

A dotted element field path and optional canonical-id extraction regex.

The arm uses it to turn each element that a reply cites into the canonical source id of a Citation.

attributefieldstr

The dotted path of the field in the element that holds the id, for example "metadata.unit_id".

attributeregexstr | None
= None

A regular expression that finds the id in the field's value, or None to take the whole value. The id is the first capture group, or the whole match without a group.

methodsource_id(element) -> str | None

Resolve a source id using the first capture group or the whole match.

paramelementMapping[str, object]

An element of a tool output, as JSON.

Returns

str | None

The canonical source id, or None when the field is missing or empty, or when the regex does not match.

CorpusLookupConfig

modelCorpusLookupConfig

Where the corpus criteria find the ids and the text of the corpus.

The project loader reads the file when it exists. Each line is a JSON object with an id and a text. Without the file, the criteria that need the corpus give a verdict with the status "error".

attributepathstr
= 'corpus/units.jsonl'

The path of the JSONL file, relative to the folder of the project file.

attributelaw_namesdict[str, list[str]]
= dict()

Other names of each law, by canonical law id. citations.mentions_in_corpus resolves a mention of such a name to that law.

SplitConfig

modelSplitConfig

Incremental lineage split targets and suite-specific strata.

The settings of a dataset split. No command of soev_evals reads them.

attributetest_sharefloat
= 0.2

The share of the lineages of each stratum that goes to the test side, from 0 to 1.

attributeseedint
= 0

The seed that orders the lineages of a stratum before the split.

attributestratifydict[str, StratifyKey]
= dict()

The StratifyKey of each suite, by suite name. A suite without an entry uses "category".

attributemin_per_sideint
= 2

The number of lineages on each side of a stratum below which a split count warns.

StratifyKey

type aliasStratifyKey = Literal['category', 'suite', 'rule', 'rule_direction']

The case field that groups the lineages of a suite into strata for a dataset split.

The split puts the same share of each stratum on the test side. The value comes from the root case of a lineage. "rule_direction" combines the rule with the expected behaviour: "pass" for "answer", "fire" otherwise.

ProjectError

errorProjectError

Project content is invalid or inconsistent.

The project loader of soev_evals.cli raises it, for example when two suites of a project have a case with the same id.

Criteria

A criterion names a kind and its parameters. The registry finds the kind, and the kind gives the verdict.

CriterionSpec

modelCriterionSpec

A named criterion with scoring policy and kind-specific parameters.

It is one entry of criteria, defaults or invariants in a YAML file. The parameters of the kind can stand next to kind, or under params. A key next to kind replaces the same key under params:

- kind: reply.max_length
  max: 2000
  gate: true
attributekindstr

The name of the criterion kind in the registry, for example "reply.language".

attributeweightint
= 1

The weight of the criterion in the score of an attempt, at least 1.

attributegatebool
= False

If true, a failed criterion makes the score of the attempt 0, and its weight does not count.

attributeparamsdict[str, JsonValue]
= dict()

The parameters of the kind. The registry validates them against the parameter model of the kind.

CriterionKind

protocolCriterionKind

A criterion implementation with a validated parameter model.

A criterion in a suite names its kind in kind. Builtin of soev_evals.criteria makes a kind of a typed async function. Register your own kinds in the CRITERIA list of the project's hooks module.

attributenamestr

The stable registry key.

It is the kind of a criterion in a suite, for example "reply.language".

attributeparams_modeltype[BaseModel]

The schema accepted by this kind.

It is a pydantic model. The registry validates the parameters of each criterion against it.

methodevaluateasync (case, evidence, *, params, ctx) -> Verdict

Evaluate one case against the supplied evidence.

Return a verdict with the status "error" when the criterion cannot grade. An exception stops the run.

paramcaseCase

The case that the attempt ran.

paramevidenceEvidence

The evidence of the attempt.

paramparamsBaseModel

The parameters of the criterion, as an instance of params_model.

paramctxCriterionContext

The services and the lookup data of the project.

Returns

Verdict

The verdict. The registry fills in its kind, weight and gate.

CriterionRegistry

classCriterionRegistry(kinds=())

Resolve and evaluate an explicitly supplied collection of kinds.

builtin_registry of soev_evals.criteria returns a registry with the built-in kinds.

Make a registry of kinds.

paramkindsIterable[CriterionKind]
= ()

The criterion kinds. Each name occurs once.

Raises:

  • DuplicateCriterionError: Two kinds have the same name.
attributenamestuple[str, ...]

The registered names, in deterministic (sorted) order.

methodkind_named(name) -> CriterionKind

Return the kind with the name name.

paramnamestr

The name of the kind.

Returns

CriterionKind

The kind with this name.

Raises:

  • UnknownCriterionError: The registry has no kind with this name.
methodvalidate(spec) -> BaseModel

Validate kind-specific arguments before evaluation begins.

paramspecCriterionSpec

The criterion to check.

Returns

BaseModel

The parameters of spec, as an instance of the parameter model of its kind.

Raises:

  • UnknownCriterionError: The registry has no kind with the name spec.kind.
  • CriterionParamsError: The parameters do not fit the parameter model of the kind.
methodevaluateasync (spec, case, *, evidence, ctx) -> Verdict

Evaluate a criterion and attach its declared weight and gate.

paramspecCriterionSpec

The criterion.

paramcaseCase

The case that the attempt ran.

paramevidenceEvidence

The evidence of the attempt.

paramctxCriterionContext

The services and the lookup data of the project.

Returns

Verdict

The verdict of the kind, with the kind, weight and gate of spec.

Raises:

  • UnknownCriterionError: The registry has no kind with the name spec.kind.
  • CriterionParamsError: The parameters do not fit the parameter model of the kind.

CriterionContext

dataclassCriterionContext(judge=None, language_detector=None, messages=dict(), corpus_ids=None, corpus_law_names=dict(), corpus_text=None, rubrics=dict())

The services and the project lookup data that each criterion gets.

Each criterion gets the same context. A criterion does no I/O of its own: what it needs from outside comes from here. A service or lookup that the project did not configure is None or empty, and a criterion that needs it gives a verdict with the status "error".

paramjudgeJudge | None
= None

The judge for the judge criteria, or None.

paramlanguage_detectorLanguageDetector | None
= None

The language detector for reply.language, or None.

parammessagesMapping[str, str]
= dict()

The fixed messages of the system, by key, from Project.messages.

paramcorpus_idsfrozenset[str] | None
= None

The ids of all corpus units, or None without a corpus lookup.

paramcorpus_law_namesMapping[str, list[str]]
= dict()

Other names of each law, by canonical law id, from CorpusLookupConfig.law_names.

paramcorpus_textMapping[str, str] | None
= None

The text of each corpus unit, by id, or None without a corpus lookup.

paramrubricsMapping[str, str]
= dict()

The text of each rubric, by the path that a rubric.judge criterion gives.

Verdict

modelVerdict

One criterion outcome with the scoring policy used for the attempt.

attributestatusLiteral['pass', 'fail', 'not_applicable', 'error']

"pass" or "fail". "not_applicable" when the case gives the criterion nothing to check. "error" when the criterion cannot grade, for example without a judge. An error makes the attempt fail, but does not count in its score.

attributedetailstr
= ''

A short explanation of the outcome.

attributedatadict[str, JsonValue] | None
= None

Structured data of the outcome for the report, or None.

attributekindstr
= ''

The kind of the criterion. The registry fills it in.

attributeweightint
= 1

The weight of the criterion. The registry fills it in.

attributegatebool
= False

Whether the criterion is a gate. The registry fills it in.

UnknownCriterionError

errorUnknownCriterionError

A criterion name is absent from the registry.

CriterionRegistry raises it for a spec whose kind it does not hold. load_suite reports it as a SuiteError.

DuplicateCriterionError

errorDuplicateCriterionError

Two implementations claim the same criterion name.

CriterionRegistry raises it when it is made with two kinds of the same name, for example a project hook that reuses the name of a built-in kind.

CriterionParamsError

errorCriterionParamsError

A criterion has invalid parameters.

CriterionRegistry.validate and CriterionRegistry.evaluate raise it when the parameters of a spec do not fit the parameter model of its kind. load_suite reports it as a SuiteError.

Evidence and scores

Evidence is what the system under test returned in one attempt. The verdicts of an attempt give its score.

Evidence

modelEvidence

The evidence of one attempt: its turns in order, its failure and the evidence of its variants.

The runner builds it for each attempt, and the criteria grade it. The archive stores it, so a rescore can grade it again without a new conversation.

attributeturnslist[TurnEvidence]
= list()

The evidence of each turn that ran, in order.

attributeartifactsdict[str, JsonValue]
= dict()

Free JSON data of the attempt. CaseSetup.collect adds its data here.

attributethread_idstr | None
= None

The id of the conversation in the system under test, or None.

attributefailurestr | None
= None

What went wrong outside a turn, for example an ArmError or a SetupError, or None.

attributevariantsdict[str, Evidence]
= dict()

The evidence of each variant of the case, by variant name.

attributereplystr | None

The final turn's reply, or None when it was not captured.

attributecited_idsfrozenset[str]

Canonical ids cited anywhere in the conversation.

attributefailurestuple[str, ...]

All recorded attempt and turn failures.

TurnEvidence

modelTurnEvidence

The reply, citations, tool calls and measurements from one turn.

A Conversation returns it for each turn that it sends. A turn with a failure ends the conversation: the runner sends no more turns of the case.

attributereplystr | None
= None

The text of the final reply, or None when the turn has none.

attributecitationslist[Citation]
= list()

The citations of the turn, in order.

attributetool_callslist[ToolCall]
= list()

The tool calls of the turn, in order.

attributeusageUsage | None
= None

The measured usage, or None when it was not measured.

attributeartifactsdict[str, JsonValue]
= dict()

Free JSON data of the turn, which criteria can read.

attributethread_idstr | None
= None

The id of the conversation in the system under test, or None.

attributefailurestr | None
= None

What went wrong in the turn, or None when nothing did.

Citation

modelCitation

A cited source resolved to its canonical id.

attributesource_idstr

The canonical id of the source, which the citation criteria compare with SourceRoles.

attributerawJsonValue
= None

The citation as the system under test returned it.

attributetitlestr | None
= None

The title of the source, or None.

attributeurlstr | None
= None

The URL of the source, or None.

ToolCall

modelToolCall

A tool invocation and a compact result description.

attributenamestr

The name of the tool.

attributeargsdict[str, JsonValue]
= dict()

The arguments of the call.

attributeresult_summarystr | None
= None

A short text form of the result, or None when the call has no result.

Usage

modelUsage

Measured token and time consumption of a turn.

attributeprompt_tokensint
= 0

The prompt tokens of all model calls of the turn.

attributecompletion_tokensint
= 0

The completion tokens of all model calls of the turn.

attributesecondsfloat
= 0.0

The duration of the turn, in seconds.

attributeanswered_modelstr | None
= None

The name of the model that wrote the reply, or None when unknown.

ScoredAttempt

modelScoredAttempt

A case's verdicts from one attempt.

attributecaseCase

The case of the attempt.

attributeverdictslist[Verdict]
= list()

One verdict for each criterion of the case, in the order of the criteria.

attributescorefloat

The weighted non-gate score, zeroed by a failed gate.

It is the weight of the passed criteria divided by the weight of the passed and failed criteria, from 0 to 1. Verdicts with the status "error" or "not_applicable" do not count. A gate that fails makes the score 0. Without a passed or failed criterion that is not a gate, the score is 1.

attributepassedbool

Whether every applicable criterion passed without judging errors.

Each verdict must have the status "pass" or "not_applicable". A verdict with the status "error" makes the attempt fail.

Ports

A port is a boundary that the caller implements: the system under test, the setup of a case, the judge, the language detector, the archive and the tracker.

Arm

protocolArm

An arm, which starts a new conversation with the system under test for each attempt.

The arm is the connection to the system under test. SoevThreadArm of soev_evals.arms is the built-in arm.

methodstartasync (case) -> Conversation

Create an isolated conversation for one attempt.

The runner calls it for each attempt of a case, and again for each variant.

paramcaseCase

The case of the attempt. For a variant, its turns are the turns of the variant.

Returns

Conversation

A new conversation that shares no state with other conversations.

Raises:

  • ArmError: The arm cannot start a conversation. The runner records it as the failure of the evidence.

Conversation

protocolConversation

A single isolated multi-turn interaction with the system under test.

An Arm starts it. The runner sends the turns of the case in order, then closes the conversation.

methodsendasync (turn) -> TurnEvidence

Submit a prompt and collect that turn's evidence.

Put a failure of the turn in TurnEvidence.failure. The runner then sends no more turns.

paramturnTurn

The next turn of the case.

Returns

TurnEvidence

The evidence of the turn.

Raises:

  • ArmError: The conversation cannot continue. The runner records it as the failure of the evidence.
methodcloseasync () -> None

Release resources associated with the conversation.

The runner calls it once after the last turn, also when a turn failed.

Raises:

  • ArmError: The release failed. The runner records it as the failure of the evidence.

CaseSetup

protocolCaseSetup

The setup of a project, which manages project-specific fixtures and artifacts around an attempt.

The runner calls prepare before the conversation, collect after it, and cleanup at the end. It does this for the turns of the case and again for each variant. Give a setup to the CLI as SETUP in the project's hooks module.

methodprepareasync (case) -> Mapping[str, JsonValue]

Prepare fixtures and return opaque cleanup state.

paramcaseCase

The case of the attempt.

Returns

Mapping[str, JsonValue]

The state that collect and cleanup receive.

Raises:

  • SetupError: The preparation failed. The conversation does not run, and the runner records the failure.
methodcollectasync (case, evidence, *, state) -> dict[str, JsonValue]

Collect project artifacts after the attempt.

paramcaseCase

The case of the attempt.

paramevidenceEvidence

The evidence of the conversation.

paramstateMapping[str, JsonValue]

The state that prepare returned.

Returns

dict[str, JsonValue]

The artifacts. The runner adds them to Evidence.artifacts.

Raises:

  • SetupError: The collection failed. The runner records the failure in the evidence.
methodcleanupasync (case, state) -> None

Release the prepared fixtures.

The runner calls it after each successful prepare, also when the conversation or collect failed.

paramcaseCase

The case of the attempt.

paramstateMapping[str, JsonValue]

The state that prepare returned.

Raises:

  • SetupError: The cleanup failed. The runner records the failure in the evidence.

Judge

protocolJudge

A judge, which gives a label for a grading request.

The judge owns the prompts. A criterion gets a judge from CriterionContext.judge. LLMJudge of soev_evals.judges is the built-in judge.

methodjudgeasync (request) -> JudgeResult

Return an allowed label or raise JudgeError.

paramrequestJudgeRequest

The task, the inputs and the allowed labels.

Returns

JudgeResult

The chosen label, one of request.allowed_labels, and its explanation.

Raises:

  • JudgeError: The judge cannot give a usable result.

JudgeRequest

modelJudgeRequest

The task and the inputs that a criterion sends to a judge.

A criterion sends the task and the inputs. The judge adds the prompt of the task.

attributetaskstr

The name of the grading task. The built-in judge criteria use their own kind as the task, for example "rubric.judge". LLMJudge picks its prompt by this name.

attributeinputsdict[str, JsonValue]

The data to grade, for example the reply and the reference answer.

attributeallowed_labelslist[str]

The labels that the judge can choose from. There is at least one.

attributecontext_prefixstr
= ''

Text that comes before the prompt, for example source text, or an empty string. With a prefix, LLMJudge first checks that the request fits the model's context window.

JudgeResult

modelJudgeResult

A judge's chosen label and explanation.

attributelabelstr

The chosen label, one of the request's allowed_labels.

attributedetailstr
= ''

The judge's explanation of the label.

attributelimitationslist[str]
= list()

The reasons for a limited answerability. Only a task with the name "filters.answerable" fills them, and no built-in criterion uses that task.

attributesource_hintslist[str]
= list()

Ids of sources that can help a reviewer. Only a task with the name "filters.answerable" fills them, and no built-in criterion uses that task.

LanguageDetector

protocolLanguageDetector

A language detector, which identifies the language of a single sentence.

The reply.language criterion calls it for each sentence of the reply. LangidDetector of soev_evals.judges is the built-in detector.

methoddetect(text) -> str

Return a language code or raise LanguageDetectionError.

paramtextstr

One sentence.

Returns

str

The language code, for example "nl". The criterion compares it with its language parameter, without case.

Raises:

  • LanguageDetectionError: The detector cannot identify the language.

RunArchive

protocolRunArchive

A run archive, which persists and retrieves complete runs for resume and rescore.

A run has a manifest, a journal of completed attempts, the evidence of each attempt and a report. The runner calls these synchronous methods in a worker thread. FileRunArchive of soev_evals.run is the built-in archive.

methodcreate(run_id, manifest) -> None

Create a run with its manifest.

paramrun_idstr

The id of the new run.

parammanifestMapping[str, JsonValue]

The manifest of the run, as JSON.

Raises:

  • ArchiveError: The run exists already, or the archive cannot write it.
methodappend(run_id, attempt) -> None

Append a completed attempt to the journal.

The runner saves the evidence of the attempt before it appends the attempt.

paramrun_idstr

The id of the run.

paramattemptMapping[str, JsonValue]

The completed attempt, as JSON.

Raises:

  • ArchiveError: The archive cannot write the journal.
methodattempts(run_id) -> Sequence[Mapping[str, JsonValue]]

Read the completed attempt journal.

paramrun_idstr

The id of the run.

Returns

Sequence[Mapping[str, JsonValue]]

The completed attempts, in the order of the journal.

Raises:

  • ArchiveError: The archive cannot read the journal.
methodsave_evidence(run_id, case_id, *, attempt, evidence) -> None

Persist evidence for a numbered attempt.

paramrun_idstr

The id of the run.

paramcase_idstr

The id of the case.

paramattemptint

The number of the attempt, from 1.

paramevidenceEvidence

The evidence of the attempt.

Raises:

  • ArchiveError: The archive cannot write the evidence.
methodload_evidence(run_id, case_id, *, attempt) -> Evidence

Read evidence for a numbered attempt.

paramrun_idstr

The id of the run.

paramcase_idstr

The id of the case.

paramattemptint

The number of the attempt, from 1.

Returns

Evidence

The evidence that save_evidence saved.

Raises:

  • ArchiveError: The archive cannot read the evidence.
methodmanifest(run_id) -> Mapping[str, JsonValue]

Read a run's manifest.

paramrun_idstr

The id of the run.

Returns

Mapping[str, JsonValue]

The manifest that create saved.

Raises:

  • ArchiveError: The archive cannot read the manifest.
methodsave_report(run_id, report) -> None

Persist the aggregate report.

A rescore calls it again and replaces the report.

paramrun_idstr

The id of the run.

paramreportMapping[str, JsonValue]

The report, as JSON.

Raises:

  • ArchiveError: The archive cannot write the report.

Tracker

protocolTracker

A tracker, which publishes run records to an optional tracking destination.

The runner logs a warning for each exception of a tracker and continues, so a tracker cannot make a run fail.

methodstartasync (run_id, manifest) -> None

Begin tracking a run and its manifest.

paramrun_idstr

The id of the run.

parammanifestMapping[str, JsonValue]

The manifest of the run, as JSON.

methodrecordasync (run_id, attempt) -> None

Publish one attempt and its evidence.

paramrun_idstr

The id of the run.

paramattemptMapping[str, JsonValue]

The attempt as the journal records it, with its evidence under the key "evidence".

methodfinishasync (run_id, report) -> None

Publish the report and finish tracking.

paramrun_idstr

The id of the run.

paramreportMapping[str, JsonValue]

The report of the run, as JSON.

ArmError

errorArmError

The system under test could not complete a conversation.

An Arm or a Conversation raises it. The runner records it as the failure of the attempt's evidence, and the run continues.

SetupError

errorSetupError

Case preparation, collection or cleanup failed.

A CaseSetup raises it. The runner records it as the failure of the attempt's evidence, and the run continues.

JudgeError

errorJudgeError

The judge could not produce a usable result.

A Judge raises it. LLMJudge raises it when it has no prompt for the task, and when the model's answer is not valid JSON or has a label that the request does not allow. It also raises it when a request with a context prefix does not fit the model's context window. A built-in criterion records it as a verdict with the status "error".

LanguageDetectionError

errorLanguageDetectionError

The detector could not identify a sentence's language.

A LanguageDetector raises it, for example for an empty sentence. The reply.language criterion records it as a verdict with the status "error".

ArchiveError

errorArchiveError

Run archive data could not be read or written.

A RunArchive raises it. The runner also raises it when a resumed run does not match its archive.

Base classes

The models of this package are frozen pydantic models, and its errors share one base class.

FrozenModel

modelFrozenModel

A frozen value object that rejects unexpected fields.

It is the pydantic base of the public models of soev_evals. A field name that the model does not declare fails validation, and so do the float values inf and nan. An instance cannot change after it is made. Subclass it for the parameter model of your own CriterionKind, so that a typo in a suite file fails when the suite loads.

EvalsError

errorEvalsError

An evaluation operation could not be completed.

It is the base class of the errors of soev_evals. Catch it to handle any of them.

On this page