Tutorial 3

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.

Emailclassify_emailLLM → one categoryextractorrules by defaultgenerate_responseLLM → replyReply
The short version. The class diagram and the method pipeline below are the same path, opened up.

The classes Who holds what

The agent owns one extractor. Both extractors implement extract. default_workflow_client installs the rule one.

extractorBaseExtractorextract(email, category) → dictkeys depend on the categoryabstract; the subclass decides howDeterministicExtractorextract routes by category_extract_bug_infoversion, error code_extract_billing_infoinvoice, amount_extract_feature_infofeature, area, urgencyregex only, no LLMLLMExtractorclient: OpenAIextract(email, category)JSON prompt, then parsesame keys as the rules if the call fails<<workflow>>ConfigurableSupportTriageAgentclient: OpenAIextractor: BaseExtractortraces: list of TraceEventextraction_modeset_extractor(extractor)classify_email(email)extract_info(email, category)generate_response(category, info)process_email(email)export_traces_to_logdefault_workflow_clientbuilds the agent and theextractor together
Hollow arrow: both extractors are a BaseExtractor. Diamond: the agent has an extractor.

The pipeline One email, three steps

process_email classifies, extracts, then generates. The two extractors are alternatives. Only one of them runs.

process_email resets traces, then runs the three stepsprocess_emailclassify_emailagent LLM → categoryextract_infodefaultDeterministicExtractoroptionalLLMExtractorgenerate_responseagent LLM → templatecategory, extracted_info, response_templateexport_traces_to_log
The branch is a choice of extractor, not two extractions. Smoke-test one email with python -m ragas_examples.workflow_eval.workflow.
MethodWhat it doesWhat it returns
classify_emailAsks the agent LLM for Billing, Bug Report, or Feature Request. Temperature 0. On error, falls back.a category string
extract_infoCalls extractor.extract and logs which fields came back.a dict of optional strings
DeterministicExtractor.extractRoutes to a regex helper for that category. Bug reports yield version and error code. Billing yields invoice and amount.those fields, or nulls
LLMExtractor.extractSends a category prompt to its own client and parses the JSON. A failed call becomes an empty dict.the same keys
generate_responsePasses the category and the extracted JSON to the agent LLM and asks for the reply.the template string
process_emailRuns the three steps, then writes the trace log. A crash still writes the log and returns a fallback reply.category, fields, template, mode
The default extractor never calls the LLM. 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,
    }
What is scored is 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.