← Back to Pull requests

Write Evaluate CSV and JSON exports as UTF-8 #10887

Closed
unknown closed this pull request without merging on Nov 15, 2026 16:04 UTC
View on GitHub
unknown unknown commented on Nov 15, 2026 14:44 UTC
Author

What this does

Evaluate(save_as_csv=...) opened its file with the platform default encoding: on Windows with a cp936/cp1252 locale a result containing a character the locale cannot encode raises UnicodeEncodeError and no CSV is produced. save_as_json had the same missing encoding=, and survived only because json.dump escapes non-ASCII by default.

Both exports now open their file with encoding="utf-8".

Reproduction (before)

Windows 11, locale.getpreferredencoding(False) == "cp936":

import tempfile
from pathlib import Path

import dspy
from dspy.evaluate import Evaluate


def program(question):
    return dspy.Prediction(answer="中文 🔥")


def metric(example, prediction, trace=None):
    return 1.0


devset = [dspy.Example(question="q", answer="中文 🔥").with_inputs("question")]
evaluator = Evaluate(devset=devset, metric=metric, display_progress=False)
evaluator(program, save_as_csv=str(Path(tempfile.mkdtemp()) / "results.csv"))

csv.py:164: UnicodeEncodeError: 'gbk' codec can't encode character '\U0001f525' in position 5: illegal multibyte sequence

Tests

tests/evaluate/test_evaluate.py::test_evaluate_save_as_csv_writes_utf8 runs a Predict over a DummyLM whose answer contains 中文 🔥, exports the results and asserts the CSV decodes as UTF-8.

Locally on main the test fails with the UnicodeEncodeError above; with the patch it passes.

tests/evaluate/test_evaluate.py as a whole has the same 9 failures before and after this change (pre-existing in this environment), with the new test added to the passing set (37 → 38 passed).

Fixes #10886

Diff: 202 lines (+151 / -51) across 2 files Reviewer: simin-yuan Review duration: 79m
All Vouch review confidence checks passed
Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 202 lines diff across 2 files
0.36
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.318
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #10887"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 36.2% (MEDIUM) · Higher = larger blast radius
36.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 14.3% · Safe to merge
14.3%