feat(test_case): make trace_dict public for post-hoc agentic evaluation#2600
Open
tiffanychum wants to merge 1 commit intoconfident-ai:mainfrom
Open
feat(test_case): make trace_dict public for post-hoc agentic evaluation#2600tiffanychum wants to merge 1 commit intoconfident-ai:mainfrom
tiffanychum wants to merge 1 commit intoconfident-ai:mainfrom
Conversation
…evaluation
`LLMTestCase._trace_dict` was a `PrivateAttr`, making it impossible to
pass a pre-recorded trace at construction time. This meant the four
agentic trace metrics (TaskCompletion, StepEfficiency, PlanQuality,
PlanAdherence) could only be used with `@observe` at runtime — not from
saved logs, CI replay, or third-party pipelines.
Changes:
- `LLMTestCase._trace_dict` → public `trace_dict` field (`Field(...)`)
with `serialization_alias="traceDict"` and
`validation_alias=AliasChoices("traceDict", "trace_dict")` so both
snake_case and camelCase work in `model_validate` / JSON round-trips.
- All internal assignments in `evaluate/execute.py` (6 sites) updated
from `._trace_dict =` to `.trace_dict =` — runtime @observe path is
unchanged.
- All four agentic metrics updated from `test_case._trace_dict` to
`test_case.trace_dict`.
- Unit tests in `test_single_turn.py` updated and a new
`test_trace_dict_constructor_and_alias` test added.
- New example added at `examples/tracing/test_posthoc_evaluation.py`
showing post-hoc evaluation from a pre-recorded trace dict.
Fixes the post-hoc evaluation gap noted in the TODO comments in
task_completion.py: the non-trace path is already marked
`# TODO: Deprecate this soon`; this PR makes the trace path accessible
without runtime instrumentation.
|
@tiffanychum is attempting to deploy a commit to the Confident AI Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LLMTestCase._trace_dict→ publictrace_dictfield — the private attribute made it impossible to pass a pre-recorded trace at construction time, so the four agentic trace metrics (TaskCompletionMetric,StepEfficiencyMetric,PlanQualityMetric,PlanAdherenceMetric) only worked with@observeat runtime.serialization_alias="traceDict"+validation_alias=AliasChoices("traceDict", "trace_dict")so both snake_case and camelCase work inmodel_validateand JSON round-trips (consistent with all other fields onLLMTestCase).evaluate/execute.pyand all 4 metric files updated from._trace_dictto.trace_dict; the runtime@observepath is unchanged.Motivation
The non-trace evaluation path in
task_completion.pyis already marked:# TODO: Deprecate this soonBut until now there was no way to reach the trace path without
@observeat runtime. This PR closes that gap, enabling:Changes
deepeval/test_case/llm_test_case.py_trace_dict: PrivateAttr→trace_dict: Field(...)with aliasesdeepeval/evaluate/execute.pydeepeval/metrics/task_completion/task_completion.py_trace_dict→trace_dict(4 references)deepeval/metrics/step_efficiency/step_efficiency.py_trace_dict→trace_dict(6 references)deepeval/metrics/plan_quality/plan_quality.py_trace_dict→trace_dict(4 references)deepeval/metrics/plan_adherence/plan_adherence.py_trace_dict→trace_dict(8 references)tests/test_core/test_test_case/test_single_turn.pytest_trace_dict_constructor_and_aliastestexamples/tracing/test_posthoc_evaluation.pyTest plan
python -m pytest tests/test_core/test_test_case/test_single_turn.py -v— all existing tests pass, new alias test passespython examples/tracing/test_posthoc_evaluation.py— post-hoc evaluation runs end-to-end with a pre-recorded trace dict@observeruntime path: no behaviour change (assignments inexecute.pywrite to the same field)Related
Parallel to issue #2579 (
Turn._mcp_interactionPrivateAttr bug) — same root cause: Pydantic v2PrivateAttrfields can't be set via the constructor.