agents.common.models.grade.binary

Binary grading model for pass/fail evaluations.

This module implements a binary grading system suitable for pass/fail, yes/no, correct/incorrect, and similar binary evaluations.

Classes

BinaryGrade

Binary grading model for pass/fail evaluations.

Module Contents

class agents.common.models.grade.binary.BinaryGrade(/, **data)

Bases: haive.agents.common.models.grade.base.Grade

Binary grading model for pass/fail evaluations.

This grade model represents simple binary outcomes such as pass/fail, yes/no, correct/incorrect, acceptable/unacceptable, etc.

Parameters:

data (Any)

value

The binary grade value (True for pass/yes, False for fail/no)

grade_type

Always GradeType.BINARY

Example

# Passing grade
grade = BinaryGrade(
value=True,
justification="Response correctly identifies all key concepts",
confidence=0.95
)

# Failing grade
grade = BinaryGrade(
value=False,
justification="Response contains factual errors and misses main points",
confidence=0.88
)

# Using string values (automatically converted)
grade = BinaryGrade(
value="pass",  # Converted to True
justification="Meets minimum requirements"
)

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.

classmethod convert_value_to_bool(v)

Convert various representations to boolean.

Accepts boolean values, strings, and numbers and converts them to appropriate boolean values for grading.

Parameters:

v (Any) – Value to convert to boolean

Returns:

Boolean representation of the value

Raises:

ValueError – If the value cannot be converted to a meaningful boolean

Return type:

bool

classmethod create_fail(justification, confidence=1.0, **kwargs)

Convenience method to create a failing grade.

Parameters:
  • justification (str) – Explanation for the failing grade

  • confidence (float) – Confidence level (default 1.0)

  • **kwargs – Additional parameters for the grade

Returns:

BinaryGrade instance with value=False

Return type:

BinaryGrade

classmethod create_pass(justification, confidence=1.0, **kwargs)

Convenience method to create a passing grade.

Parameters:
  • justification (str) – Explanation for the passing grade

  • confidence (float) – Confidence level (default 1.0)

  • **kwargs – Additional parameters for the grade

Returns:

BinaryGrade instance with value=True

Return type:

BinaryGrade

flip()

Create a new BinaryGrade with the opposite value.

Useful for creating inverse grades or testing scenarios.

Returns:

New BinaryGrade instance with flipped value

Return type:

BinaryGrade

get_display_value()

Get a human-readable display value.

Returns:

“Pass” for True, “Fail” for False

Return type:

str

get_emoji_representation()

Get an emoji representation of the grade.

Returns:

✅ for pass, ❌ for fail

Return type:

str

get_normalized_score()

Get the grade as a normalized score between 0.0 and 1.0.

Returns:

1.0 for True (pass), 0.0 for False (fail)

Return type:

float

is_passing(threshold=None)

Determine if the grade represents a passing score.

For binary grades, this simply returns the boolean value. The threshold parameter is ignored for binary grades.

Parameters:

threshold (float | None) – Ignored for binary grades

Returns:

The boolean value of the grade

Return type:

bool

to_display_string()

Convert grade to a human-readable display string.

Returns:

Formatted string representation of the binary grade

Return type:

str

validate_grade_value(value)

Validate that a value can be converted to binary.

Parameters:

value (Any) – The value to validate

Returns:

True if the value can be converted to boolean, False otherwise

Return type:

bool