Label agreement
label_agreement ¶
Label-agreement scorer that compares agent output with a labelled answer.
This module provides LabelAgreementScorer, a deterministic Scorer for trainsets whose rows carry an expected label. Pass it to evolve(), evolve_group() or evolve_workflow() through the scorer= keyword instead of a critic agent.
| ATTRIBUTE | DESCRIPTION |
|---|---|
LabelAgreementScorer | Scores 1.0 when the output agrees with TYPE: |
Examples:
Score one output field of a schema agent against its label:
from gepa_adk.adapters.scoring import LabelAgreementScorer
scorer = LabelAgreementScorer(field="label")
score, metadata = scorer.score("Buy now!!!", '{"label": "spam"}', "spam")
assert score == 1.0
assert metadata["agreement"] is True
See Also
gepa_adk.ports.scorer: Protocol that LabelAgreementScorer implements.gepa_adk.adapters.scoring.critic_scorer: LLM critic scorer for outputs without a labelled answer.
Notes
Comparison is exact after str.strip(). There is no case folding, fuzzy matching or numeric tolerance.
LabelAgreementScorer ¶
Scorer that measures exact agreement between output and label.
With field set, the output is parsed as a JSON object and str(parsed[field]).strip() is compared with expected.strip(). Without field, the output and expected agree when both parse as equal JSON documents, or otherwise when their stripped texts are equal.
| ATTRIBUTE | DESCRIPTION |
|---|---|
field | Name of the output JSON field holding the label, or TYPE: |
Examples:
Evolve a schema agent against labelled rows:
from gepa_adk import LabelAgreementScorer, evolve, run_sync
trainset = [{"input": "Buy now!!!", "expected": "spam"}]
result = run_sync(
evolve(agent, trainset, scorer=LabelAgreementScorer(field="label"))
)
Notes
Adheres to the Scorer protocol. The score is 0.0 with metadata["reason"] set to "missing_expected" when the row has no label, "output_not_json" when field is set and the output does not parse, and "field_missing" when the parsed output is not an object or lacks field. Metadata always carries field, actual, expected and agreement.
Source code in src/gepa_adk/adapters/scoring/label_agreement.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
__init__ ¶
Store the output field to compare.
| PARAMETER | DESCRIPTION |
|---|---|
field | Name of the JSON field holding the label, or TYPE: |
score ¶
Score the output by agreement with the expected label.
| PARAMETER | DESCRIPTION |
|---|---|
input_text | Input given to the agent. Not used. TYPE: |
output | Agent output text. TYPE: |
expected | Label from the trainset row. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, dict[str, Any]] |
|
Source code in src/gepa_adk/adapters/scoring/label_agreement.py
async_score async ¶
async_score(
input_text: str,
output: str,
expected: str | None = None,
) -> tuple[float, dict[str, Any]]
Score asynchronously by delegating to score.
| PARAMETER | DESCRIPTION |
|---|---|
input_text | Input given to the agent. Not used. TYPE: |
output | Agent output text. TYPE: |
expected | Label from the trainset row. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
tuple[float, dict[str, Any]] | The same result as |