Commit edfa259
fix: use output for python faithfulness statements (#201)
## Summary
- Fix a bug in Python `Faithfulness` where statements were extracted
from `expected` instead of `output`, causing the scorer to evaluate the
wrong text.
- Update both sync and async `Faithfulness` paths in
`py/autoevals/ragas.py` to route statement extraction through `output`.
- Add a regression test in `py/autoevals/test_ragas.py` that uses
mismatched `output`/`expected` and input-driven mocks so the final score
depends on correct routing.
## Bug
`Faithfulness` should score whether claims in the **generated answer**
are supported by context.
In Python, it incorrectly passed `expected` to statement extraction, so
claims were taken from ground truth rather than model output.
## Fix
- In `Faithfulness._run_eval_async(...)`: change `answer=expected` ->
`answer=output`.
- In `Faithfulness._run_eval_sync(...)`: change `answer=expected` ->
`answer=output`.
- Align sync required-field validation with async by requiring `output`
as well.
## Test
Added `test_faithfulness_extracts_statements_from_output`:
- Uses different `output` and `expected`.
- Mocks `extract_statements` to derive statements from passed `answer`.
- Mocks `extract_faithfulness` to derive verdicts from context
containment.
- Ensures score behavior reflects correct routing (would fail under old
bug).
## Validation
- `uv run --extra dev --extra scipy pytest py/autoevals/test_ragas.py -k
faithfulness_extracts_statements_from_output` passed.
- Pre-commit hooks pass on commit.
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent e541f54 commit edfa259
2 files changed
Lines changed: 49 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
983 | 983 | | |
984 | 984 | | |
985 | 985 | | |
986 | | - | |
| 986 | + | |
987 | 987 | | |
988 | 988 | | |
989 | 989 | | |
| |||
1003 | 1003 | | |
1004 | 1004 | | |
1005 | 1005 | | |
1006 | | - | |
| 1006 | + | |
1007 | 1007 | | |
1008 | 1008 | | |
1009 | | - | |
1010 | | - | |
1011 | | - | |
| 1009 | + | |
1012 | 1010 | | |
1013 | 1011 | | |
1014 | 1012 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
125 | 126 | | |
126 | 127 | | |
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 | + | |
128 | 174 | | |
129 | 175 | | |
130 | 176 | | |
| |||
0 commit comments