Execution Layer¶
The execute layer runs tasks against a dataset and captures traces. It is the first of three independent layers in the ragpill pipeline:
- Execute — this module.
- Evaluate —
ragpill.evaluation. - Upload —
ragpill.upload.
execute_dataset¶
ragpill.execution.execute_dataset
async
¶
execute_dataset(testset, task=None, task_factory=None, settings=None, mlflow_tracking_uri=None, capture_traces=True)
Run every case in a dataset and return the captured outputs + traces.
The function is pure with respect to the dataset: evaluators attached to cases are not invoked. That is the Phase 2 evaluator's job. What happens here is task execution and trace capture.
Tracing backends (selected by mlflow_tracking_uri):
None— use a private temp SQLite database. The database is removed after the call, but capturedTraceobjects are copied into the returned :class:DatasetRunOutputbefore cleanup.- A URI string — trace directly to that server (dual-backend model).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
testset
|
Dataset[Any, Any, CaseMetadataT]
|
The dataset to execute. |
required |
task
|
TaskType | None
|
The task callable. Mutually exclusive with |
None
|
task_factory
|
Callable[[], TaskType] | None
|
A zero-arg callable that returns a fresh task instance
per run (use for stateful tasks). Mutually exclusive with |
None
|
settings
|
MLFlowSettings | None
|
MLflow settings; falls back to environment variables. |
None
|
mlflow_tracking_uri
|
str | None
|
Override the tracking URI. When |
None
|
capture_traces
|
bool
|
When |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
DatasetRunOutput
|
class: |
DatasetRunOutput
|
and (when |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both or neither of |
Example
from ragpill import Case, Dataset, TestCaseMetadata
from ragpill.execution import execute_dataset
ds = Dataset(cases=[Case(inputs="hi", metadata=TestCaseMetadata())])
async def my_task(q: str) -> str:
return f"answer: {q}"
run_output = await execute_dataset(ds, task=my_task)
assert run_output.cases[0].task_runs[0].output == "answer: hi"
See Also
DatasetRunOutput: the return type.
ragpill.evaluation.evaluate_results:
Phase 2 — run evaluators against a DatasetRunOutput.
Source code in src/ragpill/execution.py
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | |
DatasetRunOutput¶
ragpill.execution.DatasetRunOutput
dataclass
¶
Top-level output of :func:execute_dataset.
Attributes:
| Name | Type | Description |
|---|---|---|
cases |
list[CaseRunOutput]
|
One :class: |
tracking_uri |
str
|
The MLflow tracking URI that was active during execution. Empty string when the local temp backend was used (the temp DB is cleaned up after execution). |
mlflow_run_id |
str
|
MLflow run ID under which traces were captured. Empty when tracing was disabled or the temp backend was used. |
mlflow_experiment_id |
str
|
MLflow experiment ID under which the run was created. Empty when tracing was disabled or the temp backend was used. |
from_json
classmethod
¶
Deserialize a :class:DatasetRunOutput produced by :meth:to_json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
str
|
JSON string produced by :meth: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
DatasetRunOutput
|
class: |
DatasetRunOutput
|
serialized (trace data survives the round trip). |
Source code in src/ragpill/execution.py
to_json
¶
Serialize this output to a JSON string.
Traces are serialized via Trace.to_json(). Other fields are
preserved as-is.
Returns:
| Name | Type | Description |
|---|---|---|
str
|
A JSON string that |
|
equivalent |
str
|
class: |
Example
Source code in src/ragpill/execution.py
to_llm_text
¶
Render an exploration-focused markdown view of this run.
See :func:ragpill.report.exploration.render_dataset_run_as_exploration.
Source code in src/ragpill/execution.py
CaseRunOutput¶
ragpill.execution.CaseRunOutput
dataclass
¶
CaseRunOutput(case_name, inputs, expected_output, metadata, base_input_key, trace, trace_id, task_runs)
All runs for a single case, plus the case-level trace.
Attributes:
| Name | Type | Description |
|---|---|---|
case_name |
str
|
Display name (falls back to |
inputs |
Any
|
The task inputs for this case. |
expected_output |
Any
|
The case's expected output, if any. |
metadata |
dict[str, Any]
|
Case metadata as a plain dict (for JSON round-trip). |
base_input_key |
str
|
Hash of the inputs (no run-index suffix). |
trace |
Trace | None
|
Full case-level MLflow |
trace_id |
str
|
MLflow trace id string. |
task_runs |
list[TaskRunOutput]
|
One :class: |
TaskRunOutput¶
ragpill.execution.TaskRunOutput
dataclass
¶
Output of a single task execution (one run of one case).
Attributes:
| Name | Type | Description |
|---|---|---|
run_index |
int
|
Zero-based index of this run within the case's repeat sequence. |
input_key |
str
|
Unique key for this run, formatted as |
output |
Any
|
Return value of the task, or |
duration |
float
|
Wall-clock seconds the task took to run. |
trace |
Trace | None
|
MLflow |
run_span_id |
str
|
Span ID of the per-run parent span inside the case trace. Empty string when tracing is disabled. |
error |
str | None
|
String representation of any exception the task raised. |
See Also¶
- Evaluation Layer — run evaluators against a
DatasetRunOutput. - Upload Layer — persist results to MLflow.
- Layered Architecture Guide — the three-layer model and use cases.