|
3 | 3 | Schemas for grading tasks. |
4 | 4 |
|
5 | 5 | This module defines the data schemas used in grading tasks, including grader modes, |
6 | | -result structures, and error handling. |
| 6 | +result structures, eval feedback, and error handling. |
7 | 7 | """ |
8 | 8 |
|
9 | 9 | from enum import Enum |
10 | | -from typing import Any, Dict, List |
| 10 | +from typing import Any, Dict, List, Optional |
11 | 11 |
|
12 | 12 | from pydantic import BaseModel, Field, field_validator |
13 | 13 |
|
@@ -36,6 +36,48 @@ class GraderMode(str, Enum): |
36 | 36 | LISTWISE = "listwise" |
37 | 37 |
|
38 | 38 |
|
| 39 | +class EvalSuggestion(BaseModel): |
| 40 | + """A suggestion for improving the evaluation itself. |
| 41 | +
|
| 42 | + Used when the grader detects weak assertions, missing coverage, |
| 43 | + or assertions that would pass for clearly wrong outputs. |
| 44 | +
|
| 45 | + Attributes: |
| 46 | + assertion: The original assertion text this relates to (optional). |
| 47 | + reason: Why this suggestion is needed. |
| 48 | +
|
| 49 | + Example: |
| 50 | + >>> s = EvalSuggestion( |
| 51 | + ... assertion="The output includes the name 'John Smith'", |
| 52 | + ... reason="A hallucinated document would also pass this check" |
| 53 | + ... ) |
| 54 | + """ |
| 55 | + |
| 56 | + assertion: Optional[str] = Field(default=None, description="The assertion this relates to") |
| 57 | + reason: str = Field(description="Why this suggestion is needed") |
| 58 | + |
| 59 | + |
| 60 | +class EvalFeedback(BaseModel): |
| 61 | + """Feedback on the quality of the evaluation itself. |
| 62 | +
|
| 63 | + Follows the principle that a passing grade on a weak assertion is worse |
| 64 | + than useless — it creates false confidence. |
| 65 | +
|
| 66 | + Attributes: |
| 67 | + suggestions: List of concrete improvement suggestions. |
| 68 | + overall: Brief assessment of the eval quality. |
| 69 | +
|
| 70 | + Example: |
| 71 | + >>> f = EvalFeedback( |
| 72 | + ... suggestions=[EvalSuggestion(reason="No assertion checks correctness")], |
| 73 | + ... overall="Assertions check presence but not correctness" |
| 74 | + ... ) |
| 75 | + """ |
| 76 | + |
| 77 | + suggestions: List[EvalSuggestion] = Field(default_factory=list, description="Improvement suggestions") |
| 78 | + overall: str = Field(default="No suggestions, evals look solid", description="Brief assessment") |
| 79 | + |
| 80 | + |
39 | 81 | class GraderResult(BaseModel): |
40 | 82 | """Base class for grader results. |
41 | 83 |
|
@@ -90,6 +132,9 @@ class GraderScore(GraderResult): |
90 | 132 |
|
91 | 133 | reason: str = Field(description="reason") |
92 | 134 | score: float = Field(description="score") |
| 135 | + eval_feedback: Optional[EvalFeedback] = Field( |
| 136 | + default=None, description="Feedback on the quality of the evaluation itself" |
| 137 | + ) |
93 | 138 |
|
94 | 139 |
|
95 | 140 | class GraderScoreCallback(BaseModel): |
|
0 commit comments