Debug a Failed Run and Prove the Fix
Find the first failed step of a run, save the run as a case, test a fix from your code, and read the result on the case beside the old trace.
This page shows the main loop of Risicare. You find a run that failed, you read its first failed step, you save the run as a case, and you run that case again from your code after you change the code. The case then shows the new result beside the old failure.
Find the failed run
Open Traces and find a run that failed.
Read the first failed step
The trace page names the first step that failed and opens on it.
Save the run as a case
Click Save as a case. The case keeps the input and the error of the first failed step.
Get the file
In the case, click Test a fix from your code. Copy the file and change the one line marked EDIT.
Run it
Run the file after you change your code. Each trial is a new trace.
Read the result on the case
Open the case again. Results on this case shows the new trials beside the saved failure.
Before you start
- A project that receives traces. See the Quickstart.
- The newest SDK: Python 0.16.1 or npm 0.19.1.
- The member role or a higher role in the project. A viewer cannot save a case.
- A Secret key for the run. The file reads the key from
RISICARE_API_KEY. An Ingest key cannot read datasets, so the run stops with an error. The first key of a new project is an Ingest key. Make a Secret key in Settings → API Keys, and keep it out of your application. See Which key a run needs.
1. Find the failed run
The Traces page marks a run that failed:
| Mark | Meaning |
|---|---|
| Ended in error | The root span of the trace failed. The run itself ended in an error |
| Steps failed | A step of the trace failed, but its root span ended OK. The run ended OK |
Two filter terms list these runs. ended:error lists the runs that ended in error. error:true lists the runs with errors: the runs in which at least one span failed, an LLM call, a tool call or a step. Type a term in the filter bar. See Filter Language. Click a run to open its trace page.
2. Read the first failed step
When a step of the run failed, the trace page shows a block with the failed steps of the run. The first line says how the run ended: for example "Ended in error.", or "With errors: the run ended OK." The next line names the first failed step, for example:
First failed step: lookup_order (Tool call) · step 5 of 61 in time order · 1.20 s · KeyError.- Jump to it selects that span in the tree. The tree row has the chip First failed step.
- When all the spans of the trace are stored, the page opens with that span selected.
- A failed step is a failed span with no failed span below it. A step that failed because a step inside it failed is not the first failed step: the step inside it is.
- "A later call of the same tool ended OK." under a row means that a later call with the same parent, the same kind and the same tool name did not fail. Risicare compares the names only, not the inputs.
- Other rows can follow: First failed step with no later OK call of the same tool and Last failed step.
When only the run itself reports the error, the block says "No step inside the run failed. Only the run itself reports the error." Open the run span selects the root span.
For the member role or a higher role, the block ends with the button Save this run as a case to test a fix. It opens the panel Save as a case of the header of the page. Go on to the next step.
3. Save the run as a case
Open the form
Click Save as a case in the header of the trace page, or Save this run as a case to test a fix at the end of the block of the failed steps. Both open the same panel, Save as a case. Choose a Dataset. To make a dataset there, choose New dataset…, type a name and click Create and add. A project with no dataset asks for a name at once.
Read what the case keeps
The form says what the case will hold. For a run with a failed step it says "A step of the trace failed. The error of the first failed step is kept with the case." The line under it starts with "Error kept with the case:" and names the step and the error. The expected answer is pending.
Choose a failure class
Failure class is optional. The default is No class.
Click Add
The form says "Added as version N." with the links Open the case and Open the dataset.
The case keeps the first user message of the trace as its input, and the answer of the trace, when it has one, as evidence. The error of the first failed step is the Saved failure of the case. When the trace has no input text (content capture is off, or the SDK sent none), the form says "You can type the input in the case editor." Type the input before you run the case. A run leaves out a case with an empty input. See Datasets.
4. Get the file
Open the case: click its row on the dataset page, or click Open the case after you save it. The case shows the card Results on this case. Under the card, click Test a fix from your code. The page moves to the panel with the same title, Test a fix from your code, on the same dataset page.
- Choose Python or JavaScript.
- The panel shows the file, with its path, for example File: evals/check_my_dataset.py. Click the copy button.
- Change the one line marked
EDIT: the import of your code.answer(case_input)must return the output of your agent. - The note under the file says: "The file reads a Secret key from RISICARE_API_KEY. Create one in Settings → API Keys. An Ingest key cannot read datasets." For an owner or an admin, "Create one in Settings → API Keys." is a link that opens the dialog that creates a key, with the class Secret chosen. For another role, the link opens Settings → API Keys.
- The panel also says: "You came from a case. The file prints the address of that case, so the link at the end of the run opens its result."
The file names the dataset by its id, so a new name of the dataset does not break it. It runs the cases of the dev split of the dataset that have an input, with 3 trials for each case. At the end it prints the address of the case that you came from: the dataset page with that case open (?case=<case-id>). A file that you copy from the panel with no click on Test a fix from your code of a case, or after you load the page again, prints the address of the dataset page in its place, after the words "See the result on each case:".
This is the file for a dataset in which no case has an expected answer, copied from a case. The dashboard writes your dataset id, dataset name, project id and case id in it:
# evals/check_my_dataset.py
# Runs the cases of the dataset "my-dataset" (the dev split) through your code, 3 trials each, and stores the run in Risicare.
# Change one line: the import of your code (marked EDIT). Then run: python evals/check_my_dataset.py
# It needs a Secret key in RISICARE_API_KEY (Settings > API Keys). An Ingest key cannot read datasets.
# Written for the risicare Python package 0.15.0 or later.
import os
from risicare import evals
from my_app import answer # EDIT: import your code. answer(case_input) returns the output.
if not os.environ.get("RISICARE_API_KEY"):
raise SystemExit("Set RISICARE_API_KEY to a Secret key (Settings > API Keys). An Ingest key cannot read datasets.")
# No check. Risicare reads the trace of each trial. A trial passes when the run completes with no failed step.
# The SDK needs one required check to start a run, so this check always passes. It does not judge the answer.
def function_returned(case, output):
return True
CHECKS = [evals.Check("function_returned", function_returned)]
RELEASE = os.environ.get("GITHUB_SHA", "local")[:12]
CI_RUN = os.environ.get("GITHUB_RUN_ID")
ATTEMPT = os.environ.get("GITHUB_RUN_ATTEMPT", "1")
# Your code uses a prompt from Risicare? Pass it as prompt=get_prompt(name, version=N) (from risicare import get_prompt).
# The run then binds to that version, and it can count for the gate of that prompt.
run = evals.run(
dataset="<dataset-id>", # the id of the dataset "my-dataset"
function=lambda case: answer(case.input),
checks=CHECKS,
trials=3,
release=RELEASE,
external_id=f"{CI_RUN}-{ATTEMPT}-run" if CI_RUN else None,
)
print(f"Run: {run.id}.")
print("See the result on this case: https://app.risicare.ai/project/<project-id>/datasets/<dataset-id>?case=<case-id>")// evals/check-my-dataset.mjs
// Runs the cases of the dataset "my-dataset" (the dev split) through your code, 3 trials each, and stores the run in Risicare.
// Change one line: the import of your code (marked EDIT). Then run: node evals/check-my-dataset.mjs
// It needs a Secret key in RISICARE_API_KEY (Settings > API Keys). An Ingest key cannot read datasets.
// Written for the risicare npm package 0.18.0 or later, on Node 18 or later.
import { defineCheck, runDataset } from "risicare/evals";
import { answer } from "../src/app.js"; // EDIT: import your code. answer(caseInput) returns the output.
if (!process.env.RISICARE_API_KEY) {
throw new Error("Set RISICARE_API_KEY to a Secret key (Settings > API Keys). An Ingest key cannot read datasets.");
}
const checks = [
defineCheck({
name: "function_returned",
// No check. Risicare reads the trace of each trial. A trial passes when the run completes with no failed step.
// The SDK needs one required check to start a run, so this check always passes. It does not judge the answer.
fn: () => true,
}),
];
const release = (process.env.GITHUB_SHA ?? "local").slice(0, 12);
const ciRun = process.env.GITHUB_RUN_ID;
const attempt = process.env.GITHUB_RUN_ATTEMPT ?? "1";
// Your code uses a prompt from Risicare? Pass it as prompt: await getPrompt(name, { version: N }) (import { getPrompt } from "risicare").
// The run then binds to that version, and it can count for the gate of that prompt.
const run = await runDataset({
dataset: "<dataset-id>", // the id of the dataset "my-dataset"
fn: (c) => answer(c.input),
checks,
trials: 3,
release,
...(ciRun ? { externalId: `${ciRun}-${attempt}-run` } : {}),
});
console.log(`Run: ${run.id}.`);
console.log("See the result on this case: https://app.risicare.ai/project/<project-id>/datasets/<dataset-id>?case=<case-id>");The panel reads how many cases of the dataset have an expected answer, and it gives one of three files:
| Cases of the dataset | The check in the file | CI file |
|---|---|---|
| No case has an expected answer | function_returned only, as above. The note says "No case has an expected answer, so the file has no check on the answer. Risicare reads the trace of each trial." | Not shown. The panel says "The CI gate needs a check. Add expected answers first." |
| Some cases have one | function_returned decides. contains_expected is an extra check (required=False). It gives no result for a case with no expected answer | Not shown |
| Every case has one | contains_expected is the required check | Shown, with the gate line |
A case in the holdout split is not in the file run. The line above the button then says to set split="holdout" in evals.run (split: "holdout" in runDataset). See The holdout.
5. Run it
Change your code, then run the file:
export RISICARE_API_KEY=<your Secret key>
python evals/check_my_dataset.py # JavaScript: node evals/check-my-dataset.mjsThe file prints Run: <run id>. and the line "See the result on this case:" with the address of the case. Open that address to read the result. Each trial runs in your process and makes one trace. See Run from Code.
6. Read the result on the case
Open the case. The card Results on this case has two columns:
- Saved failure: the source trace of the case with Open the trace, and the first failed step with its error, as the case keeps them. A case with no saved failure says "This case keeps no failed step."
- Newest run: the newest run of the dataset that has a result for this case, with the tag Run from your code. It has one sentence for the case, and one line for each trial with Open the trace.
Older runs lists the older runs, one line for each run. So the new trace of each trial is beside the old trace of the failure.
Risicare reads the trace of each trial to give the result. It reads no trace less than 2 minutes after the result, because spans can still arrive. It reads the traces when you open the case or the run page. Read again reads the trials that are not read yet. While a trial is not read, the card says, for example, "2 of 3 trials read. The traces are read 2 minutes after the run. Use Read again to read the others."
The result of the case
The sentence of the case starts with one of these words:
| Words | When |
|---|---|
| Not known yet | A trial is not read yet. For about the first 2 minutes after the run, this is the usual result: "Not known yet: 0 of 3 trials read. The traces are read 2 minutes after the run." |
| Passed | Every trial completed with no failed step. "Passed: 3 of 3 trials completed with no failed step." |
| Completed with a failed step | Every trial ended OK, but in at least one trial a step failed and a later call of the same step ended OK. The card shows this in the warning colour, never as a pass. It says "Risicare cannot tell a retry from a later call with another input." Open the trace of that trial to check |
| Mixed | Some trials ended OK and some failed. The sentence ends "A mixed result is not a pass." |
| Failed | No trial ended OK. "Failed: 0 of 3 trials completed with no failed step." |
| Failed so far | A trial failed, and a trial is not read yet |
| Not known | Risicare cannot read a result for a trial. The sentence gives the reason, for example "the trace of trial 2 did not arrive in 24 hours." |
The line of each trial
| Line | Meaning |
|---|---|
| "Trial 1: completed with no failed step." | No span of the trial failed |
| "Trial 2: ended OK. search (Tool call) failed, and a later call of the same step ended OK." | The step recovered. This trial makes the case Completed with a failed step |
| "Trial 3: the run ended OK, but lookup_order failed and no later call of it ended OK." | A failed trial |
| "Trial 1: your function raised an error: KeyError." | Your function raised. A failed trial |
| "Trial 2: not read yet. The traces are read 2 minutes after the run." | Read it again later |
| "Trial 2: not known: …" | The reason follows |
When your function raised, and the step that failed is inside the run, the line compares that step with the saved failure of the case:
- "It failed at the same step as the saved failure: lookup_order (Tool call)." The step has the same name and kind as the saved step, and the same error code (or the same error type when the case keeps no code).
- "It failed at a different step: search (Tool call). The saved failure was at lookup_order."
When a run has a required check on the answer, a line under the sentence says, for example, "Your check contains_expected: true in 2 of 3 trials." The check does not change the result of the case.
The rule, and what it does not prove
The result of a case reads the trace of each trial. A trial passes when the run completes with no failed step. This rule does not read the answer. A trial that gives a wrong answer with no failed step passes.
A case with no expected answer has nothing to check. The file for such cases has the required check function_returned, which always passes. When a run of that file includes cases with no expected answer, Risicare treats it as a run with no check on the answer:
- The run page shows "No required check" in place of a pass rate, for example "No required check. Each trial is judged by its run: 3 of 3 trials completed with no failed step."
- Risicare never picks the run as a baseline. A comparison with it as the baseline gives no verdict.
- The run is never evidence for the production gate of a prompt.
risicare eval gategives no verdict for it, with any flag or with no flag, and exits with code 101. It prints "No verdict: The run has no required check that judges the answer, so it is not evidence for a gate. allow_no_verdict does not allow it." See The Gate.
To judge the answers, set the expected answer of each case in the case editor. When every case has one, the panel gives the file with the check contains_expected and the CI file.
Known limits of the rule
- Risicare compares the names of the steps, not the inputs. A later OK call with the same parent, kind and name can make a failed step "recovered". A loop over items, or a later turn of an agent, can do this too. Such a trial reads "ended OK" with a failed step, and the case reads Completed with a failed step, never Passed.
- A retry that recovers inside a step reads Completed with a failed step, not Passed: a step did fail.
- A retry of a whole step reads as a failure. When a step fails because a step inside it failed, and your code runs the whole step again, the inner failed call and its next call have different parents. The trial then reads as failed.
- An error that no span records is not seen. For example, your code catches an error in code that no span covers.
- A trace with more than 20,000 spans gives Not known: Risicare does not read its failed steps.
- A trace that does not arrive in 24 hours, or whose top span does not arrive, gives Not known.
JavaScript (npm 0.19.1)
What works:
runDatasetanddefineCheckfromrisicare/evals, and the.mjsfile of the panel.npx risicare eval gatein CI.- The result on the case, as for Python.
What does not work:
- The text of a prompt is captured only by
patchOpenAIandpatchAnthropic. The other JavaScript provider patches send no prompt text and no completion text. The LangChain.js handler sends counts only, for example the number of prompts. See Providers. - So a case that you save from such a trace has no input. Type the input in the case editor before you run the case. A run leaves out a case with an empty input.
- npm has no pytest plugin. Run the file, or call
runDatasetin your own test.