An AI workflow needs inspectable inputs, outputs and handoff points. Scheduling, legal intake and customer support have different business rules, but they can share the same boundary: the model proposes an action, application code checks it and a person handles unresolved cases.
The first instinct is to build a single long chain: user message → LLM classification → action → response. That works for demos. In production, it breaks the moment you need to handle a message that doesn't fit your categories, or when the LLM hallucinates an appointment time that doesn't exist in the calendar.
What works better is what I call a 'checkpoint architecture.' Every step in the workflow produces an inspectable artifact: the raw input, the classified intent, the extracted entities, the proposed action, and the confirmation. If any step fails, the system falls back to a human handoff instead of sending garbage to the user.
For ClinicaSync, the workflow is: incoming WhatsApp message → intent classification (new booking, reschedule, cancel, question) → entity extraction (date, time, doctor name) → calendar availability check → confirmation message → booking creation. Each of those steps logs its input and output. When a patient writes 'quero marcar pra terça com o Dr. Silva,' the system extracts the entities, checks Dr. Silva's Tuesday slots, and proposes specific times.
Validate dates between entity extraction and the availability check. If the parsed date is in the past, the timezone is missing or Tuesday could refer to two different dates, ask for clarification. Log the rejected value and the next action so you can investigate failures without guessing.
For legal intake, collect the case type, the relevant dates and a document checklist. Send a structured summary to the lawyer for review. A classifier can route an enquiry; it should not decide legal viability or give legal advice in place of a qualified professional.
Treat a model output as untrusted input. Check the schema, confirm the permissions and re-read the relevant calendar or database before a write. Use an idempotency key so a retried webhook cannot create a second booking.
Keep a trace for each workflow run: the input, the selected route, the validation result, the tool response and the final status. AgentTrace Studio documents tracing and evaluation tooling; Pydantic models document schema validation. A valid schema still needs business checks.