dspy.evaluate.EvaluationResult¶
dspy.evaluate.EvaluationResult(score: float, results: list[tuple[dspy.Example, dspy.Example, Any]]) ¶
Bases: Prediction
A class that represents the result of an evaluation. It is a subclass of dspy.Prediction that contains the following fields
- score: An float value (e.g., 67.30) representing the overall performance
- results: a list of (example, prediction, score) tuples for each example in devset
Source code in dspy/evaluate/evaluate.py
Methods:¶
copy(**kwargs) ¶
Return a shallow copy, optionally overriding fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs | Fields to add or override in the copy. | {} |
Examples:
>>> import dspy
>>> ex = dspy.Example(question="Why?", answer="Because.")
>>> ex.copy(answer="No reason.")
Example({'question': 'Why?', 'answer': 'No reason.'}) (input_keys=None)
Source code in dspy/primitives/example.py
from_completions(list_or_dict, signature=None) classmethod ¶
get(key, default=None) ¶
Return the value for key, or default if the field doesn’t exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | Field name to look up. | required | |
default | Value to return when | None |
Examples:
>>> import dspy
>>> ex = dspy.Example(name="Alice")
>>> ex.get("name")
'Alice'
>>> ex.get("city", "Unknown")
'Unknown'
Source code in dspy/primitives/example.py
get_lm_usage() ¶
inputs() ¶
Return a new Example containing only the input fields.
Requires with_inputs to have been called first.
Raises:
| Type | Description |
|---|---|
ValueError | If |
Examples:
>>> import dspy
>>> ex = dspy.Example(question="Why?", answer="Because.").with_inputs("question")
>>> ex.inputs()
Example({'question': 'Why?'}) (input_keys={'question'})
Source code in dspy/primitives/example.py
items(include_dspy=False) ¶
Return (field_name, value) pairs, like dict.items().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_dspy | If | False |
Examples:
>>> import dspy
>>> dspy.Example(question="Why?", answer="Because.").items()
[('question', 'Why?'), ('answer', 'Because.')]
Source code in dspy/primitives/example.py
keys(include_dspy=False) ¶
Return field names, like dict.keys().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_dspy | If | False |
Examples:
Source code in dspy/primitives/example.py
labels() ¶
Return a new Example containing only the label (non-input) fields.
Requires with_inputs to have been called first, since labels are everything that is not an input.
Examples:
>>> import dspy
>>> ex = dspy.Example(question="Why?", answer="Because.").with_inputs("question")
>>> ex.labels()
Example({'answer': 'Because.'}) (input_keys=None)
Source code in dspy/primitives/example.py
set_lm_usage(value) ¶
toDict() ¶
Convert to a plain dictionary, recursively serializing nested objects.
Nested Example objects, Pydantic models, lists, and dicts are converted so the result is JSON-friendly.
Examples:
>>> import dspy
>>> dspy.Example(question="Why?", answer="Because.").toDict()
{'question': 'Why?', 'answer': 'Because.'}
Source code in dspy/primitives/example.py
values(include_dspy=False) ¶
Return field values, like dict.values().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_dspy | If | False |
Examples:
Source code in dspy/primitives/example.py
with_inputs(*keys) ¶
Mark which fields are inputs and return a new Example.
Fields not listed here are treated as labels (expected outputs). DSPy optimizers and evaluators use this split: they pass example.inputs() to your program and compare the output against example.labels().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys | Names of the input fields. | () |
Returns:
| Type | Description |
|---|---|
| A copy of this |
Examples:
>>> import dspy
>>> ex = dspy.Example(question="Why?", answer="Because.").with_inputs("question")
>>> ex.inputs().keys()
['question']
>>> ex.labels().keys()
['answer']
Source code in dspy/primitives/example.py
without(*keys) ¶
Return a copy with the specified fields removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*keys | Field names to drop. | () |
Examples:
>>> import dspy
>>> ex = dspy.Example(question="Why?", answer="Because.", source="web")
>>> ex.without("source")
Example({'question': 'Why?', 'answer': 'Because.'}) (input_keys=None)