artefactual.preprocessing.Judgment#

class artefactual.preprocessing.Judgment(**data)[source]#

Bases: BaseModel

What a judge said about an answer: the verdict, and why.

This is the schema the judge prompt asks for, {“judgment”: true|false, “explanation”: “…”}, so the class can be passed as a structured-output response_format and validated like any other model. The constructors read the replies that ignored it.

Note the polarity: judgment=True means the answer was CORRECT, which is the opposite of the class a detector predicts, so a caller building labels wants not judgment. The convention is the judge prompt’s, not this package’s, and renaming it here would put the two out of step.

Parameters:
  • judgment (bool) – True when the judge said the answer was correct. Only a real boolean is accepted: bool(“false”) is True, so a judge emitting the value as a string – which a loose schema invites – would mark every wrong answer correct, silently, leaving a label distribution that still looks plausible.

  • explanation (str, default="") – The judge’s reasoning. The verdict never depends on it.

Examples

>>> Judgment.from_text('{"judgment": true, "explanation": "matches"}').judgment
True
>>> Judgment.from_text("I cannot decide.") is None
True

Methods

construct

copy

Returns a copy of the model.

dict

from_batch

Read the verdict of every line of a judge's Batch output, in line order.

from_completion

Read the verdict out of the completion that carries the judge's reply.

from_orm

from_text

Read a judge's reply, or None if it carries no verdict.

json

model_construct

Creates a new instance of the Model class with validated data.

model_copy

!!! abstract "Usage Documentation"

model_dump

!!! abstract "Usage Documentation"

model_dump_json

!!! abstract "Usage Documentation"

model_json_schema

Generates a JSON schema for a model class.

model_parametrized_name

Compute the class name for parametrizations of generic classes.

model_post_init

Override this method to perform additional initialization after __init__ and model_construct.

model_rebuild

Try to rebuild the pydantic-core schema for the model.

model_validate

Validate a pydantic model instance.

model_validate_json

!!! abstract "Usage Documentation"

model_validate_strings

Validate the given object with string data against the Pydantic model.

parse_file

parse_obj

parse_raw

schema

schema_json

update_forward_refs

validate

explanation: str#
classmethod from_batch(rows)[source]#

Read the verdict of every line of a judge’s Batch output, in line order.

One entry per row, so the result is aligned with read_batch and a caller joins on custom_id with zip(rows, Judgment.from_batch(rows)). None marks a line that failed or whose reply is unreadable: they are kept so the caller can count them, and dropping them here would silently shift every later verdict against its row.

Parameters:

rows (iterable of BatchRequestOutput) – Lines as read_batch returns them. Iterated once.

Return type:

list of Judgment or None

classmethod from_completion(completion)[source]#

Read the verdict out of the completion that carries the judge’s reply.

A failed batch line, a rejected request’s error object and a reply with no text are all None from read_message, and none of them is worth a different answer than a reply that simply could not be read: all of them are a row to drop and count. Raising would make the caller branch on which kind of nothing it got.

Parameters:

completion (Any) – A chat completion, as a mapping or an attribute-style object. A batch line’s completion is exactly this, including the None a failed line yields.

Returns:

None for an unreadable reply, a completion with no message, or no completion at all.

Return type:

Judgment or None

classmethod from_text(reply)[source]#

Read a judge’s reply, or None if it carries no verdict.

Models wrap the requested object in prose or a Markdown fence often enough that a bare json.loads is unsafe, so three readings are tried in decreasing order of trust:

  1. the reply as JSON, an object with a boolean verdict;

  2. the reply’s fenced block as JSON. Common enough to be worth its own step: the fenced object is valid JSON once the fence is gone, so this recovers the boolean rather than falling through to a substring scan that cannot tell “judgment”: true in the object from the same text quoted in prose;

  3. a scan, deliberately narrow: the key spelled as the prompt asks for it, or a reply that is nothing but true / false. Anything looser reads a verdict out of a sentence that merely discusses one. A reply carrying both verdicts has none.

A reply none of them can read returns None rather than a guess – an unreadable verdict is a row to drop and count, and a guessed one is a mislabelled row that nothing downstream can notice.

Parameters:

reply (str) – The text the judge wrote.

Returns:

The verdict, with the explanation when the JSON object has one as a string; a missing, null or non-string explanation is “”. None when no reading finds a verdict.

Return type:

Judgment or None

judgment: Annotated[bool]#
model_config: ClassVar[ConfigDict] = {}#

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