AI workflow evaluation
A workflow is several steps with a contract between them. This one classifies a support email, extracts fields, and lets an LLM write the reply. Rules are the default extractor. The metric scores the reply, not the extracted fields.
The system Classify, extract, reply
Two of the steps call the agent's LLM. Extraction is a plug-in, and the default plug-in is rules.
The classes Who holds what
The agent owns one extractor. Both extractors implement extract. default_workflow_client installs the rule one.
The pipeline One email, three steps
process_email classifies, extracts, then generates. The two extractors are alternatives. Only one of them runs.
python -m ragas_examples.workflow_eval.workflow.| Method | What it does | What it returns |
|---|---|---|
classify_email | Asks the agent LLM for Billing, Bug Report, or Feature Request. Temperature 0. On error, falls back. | a category string |
extract_info | Calls extractor.extract and logs which fields came back. | a dict of optional strings |
DeterministicExtractor.extract | Routes to a regex helper for that category. Bug reports yield version and error code. Billing yields invoice and amount. | those fields, or nulls |
LLMExtractor.extract | Sends a category prompt to its own client and parses the JSON. A failed call becomes an empty dict. | the same keys |
generate_response | Passes the category and the extracted JSON to the agent LLM and asks for the reply. | the template string |
process_email | Runs the three steps, then writes the trace log. A crash still writes the log and returns a fallback reply. | category, fields, template, mode |
classify_email and generate_response are the agent's two model calls. Swap in LLMExtractor and extraction becomes a third call, with the same return shape.The dataset email + pass criteria
Each row is an email and a checklist the reply must satisfy: category, extracted fields, and what the text must mention.
dataset_dict = [
{
"email": "Hi, I'm getting error code XYZ-123 when using version 2.1.4 of your software.",
"pass_criteria": "category Bug Report; product_version 2.1.4; error_code XYZ-123; response references both version and error code",
},
{
"email": "I need to dispute invoice #INV-2024-001 for 299.99 dollars.",
"pass_criteria": "category Billing; invoice_number INV-2024-001; amount 299.99; response references invoice and dispute process",
},
]The criteria mix structured fields (product_version 2.1.4, invoice_number INV-2024-001) with a prose requirement (“response references both version and error code”). A fail can mean the extractor missed a field or the template never used it.
The metric Checklist judge
Same DiscreteMetric shape as the RAG page. The rubric is pass_criteria instead of grading notes.
my_metric = DiscreteMetric(
name="response_quality",
prompt=(
"Evaluate the response based on the pass criteria: {pass_criteria}. "
"Does the response meet the criteria? Return 'pass' or 'fail'.\n"
"Response: {response}"
),
allowed_values=["pass", "fail"],
)The experiment Keep the reason
The judge’s reason is stored next to the score so a later run can be compared, not just counted.
@experiment()
async def run_experiment(row):
response = workflow_client.process_email(row["email"])
score = my_metric.score(
llm=llm,
response=response.get("response_template", " "),
pass_criteria=row["pass_criteria"],
)
return {
**row,
"response": response.get("response_template", " "),
"score": score.value,
"score_reason": score.reason,
}response_template, the routed reply, not the raw extractor output. If the category is wrong, this metric still fails, but you will not see the extracted fields unless you add them to the experiment view.Key takeaways
- End to end:
python -m ragas_examples.workflow_eval.evals. - Write pass criteria as a checklist of fields and mentions, then let the judge apply them.
- Persist
score.reason. A pass/fail column without a reason is hard to diff after you change the router.