Towards Reliable Generation of Executable Workflows by Foundation Models

Ask a foundation model (FM) to turn “send me AI news every morning” into an executable workflow and you’ll usually get something that looks right. Run it and it often breaks. In our TOSEM paper, we measure how often this happens, sort the failures into a taxonomy, and show that pairing an LLM with an old-fashioned static analyzer fixes far more of them than asking the LLM to check its own work.

This post is based on our paper Towards Reliable Generation of Executable Workflows by Foundation Models, written with Sogol Masoumzadeh, Keheliya Gallaba, and Ahmed E. Hassan. The paper has the full method, setup, and results.

The setting: natural language to a low-resource DSL

FM-powered applications are usually workflows: sequences of steps, where each step calls an FM, a tool, an API, or another model. Enterprise process languages like BPEL and BPMN weren’t built for FM-specific semantics, and general-purpose code gets verbose quickly. That’s why projects like LangChain’s LCEL and GenAIScript have moved toward FM-friendly DSLs.

For this study we defined WorkflowDSL, a procedural JSON language specified as a TypeScript type definition. A workflow has an inputs field, an outputs field, and a list of task nodes. Each node is a regular task, a conditional branch, a switch case, or a loop. Every task calls a skill from the execution environment. There are four kinds of skills:

  • Native: local tools, API calls, and code snippets
  • Semantic: prompts sent to an FM
  • Model: other ML models, such as a sentiment classifier
  • Workflow: calls to other WorkflowDSL programs

The NL-2-DSL pipeline has two stages. First, AlignMind refines the user’s vague request into step-by-step natural-language instructions through a multi-agent conversation. Then a Converter Agent turns those instructions into WorkflowDSL, guided by a Skill Chooser that adds the most semantically similar skills from the skill database to the prompt.

The key difference from successes like LLM-generated GitHub Actions is that a custom DSL is a low-resource language. The model has seen almost none of it during training, so it is largely guessing the syntax and semantics.

A motivating bug

Take an age-check workflow. If the user is 18 or older, approve them and send an approval message; otherwise, reject them and send a rejection message. In one generated version, the “send rejection” task on the else branch took its messageID from the ApprovalID produced on the then branch. The two branches are mutually exclusive, so that value can never exist when the task runs. We suspect the cause is autoregressive generation: the model emits the JSON token by token and assumes anything it wrote earlier is in scope. Catching this kind of bug requires reasoning about control flow and data flow, which is what compilers are good at.

RQ1: What goes wrong? A defect taxonomy

We generated workflows with GPT-4o-mini from two sources: simulated user scenarios covering different personas (cordial, neutral, rude, indecisive), expertise levels, and domains, plus real-world scenarios from the OpenAGI dataset. A researcher and an industry engineer open-coded the workflows until saturation, for a total of 65 workflows. Their agreement, measured by Cohen’s kappa, went from moderate on the calibration set to almost perfect overall. We also added a few defect types from the literature (concurrency violations, unparsable JSON, malformed expressions) to make the taxonomy complete. The result is 20 defect types in three groups:

  • Data errors: incorrect workflow inputs, incorrect outputs, and type-consistency violations
  • Logical errors: reachability violations (unreachable or unused variables), omitted logic, extra incorrect logic, and concurrency violations
  • Instruction–workflow mismatch: wrong control-flow construct or ordering, over-engineering, defective structure (unparsable JSON, invalid DSL, malformed expressions), and incorrect skill usage (wrong skill, suboptimal skill, hallucinated skill, or the right skill with defective parameters)

Defects are common. 58 of 65 workflows (89.23%) had at least one defect. The average was about 15 defects per workflow, and the worst workflow had 24. The most frequent type was correct skill with defective parameters, followed by unreachable and unused variables. Instruction–workflow mismatches made up most of the incidences.

Is this just a GPT problem? We regenerated workflows with Llama-3-70B and Qwen-7B. Both produced defects in the same categories at different rates. Defective parameters (53 for Llama, 75 for Qwen) and unreachable variables (51 for each) were again the most common. The taxonomy held across model families.

RQ2: Timon, a static analyzer for FM-generated workflows

Some defect types need a human (over-engineering, suboptimal skill choice) or need the workflow to run (concurrency). Timon covers the nine types that can be found mechanically. It works in three stages:

  1. Structure validation: parse the JSON, then instantiate it against the grammar using Pydantic. This catches unparsable JSON and invalid DSL.
  2. Intermediate representation: build a control-flow graph, then use-def and def-use chains.
  3. Defect detection: find unreachable variables (a use with no reaching definition), unused variables (a definition that is never used), type propagation errors along the chains, and malformed conditions or switch expressions (by parsing each into an AST). It also checks every action against the skill database to catch hallucinated skills and wrong I/O parameters, and verifies the required format of outputs.
Defect typeSimulated P / ROpenAGI P / R
Unparsable JSON*100% / 100%N/A
Invalid DSL100% / 100%100% / 100%
Unreachable variables50% / 71%33% / 58%
Unused variables75% / 100%53% / 89%
Incorrect type propagation37% / 72%N/A
Hallucinated skills100% / 100%100% / 100%
Skills w/ defective parameters100% / 100%100% / 100%
Malformed expressions*100% / 100%N/A
Incorrect outputs100% / 100%100% / 100%
Overall56% / 80%67% / 87%
Timon detection accuracy. *Evaluated on injected defects, since none occurred naturally.

The structural and skill checks are exact. The weaker results are in the data-flow checks, and the reason is predictable: telling a real unreachable variable apart from one that only sits on an infeasible path depends on runtime input values. Timon is designed to favor recall, so it reports most real defects at the cost of some false alarms.

RQ3: Pumbaa, verifier-in-the-loop repair

Pumbaa sends Timon’s report to an FM and asks it to fix one defect type at a time. Each prompt is tailored to its defect type: the grammar for invalid DSL, the output-format instruction for incorrect outputs, and the list of available skills for skill errors. After every attempt, Timon re-checks the workflow, so any defects Pumbaa introduces are caught and sent back for repair. We compared GPT-4o, Llama-3-70B, and Qwen-7B with up to 10 attempts per defect type (pass@10). As a baseline, we gave GPT-4o the defect definitions and few-shot examples and asked it to find and fix defects itself, without Timon.

Defect type (40 simulated workflows)DetectedBaseline (no feedback)GPT-4oLlamaQwen
Invalid DSL30000
Unreachable variables254720217
Unused variables128460160
Incorrect type propagation5501200
Hallucinated skills33333
Skills w/ defective parameters516016000
Incorrect outputs3131313131
All99045 (4.55%)286 (28.89%)71 (7.17%)41 (4.14%)
Repaired defect counts at pass@10.

The main takeaways:

  • Feedback is what makes repair work. GPT-4o with Timon’s report repaired 28.89% of defects. On its own, it repaired 4.55%. This matches earlier findings that LLMs are poor at intrinsic self-correction.
  • Model capacity matters. Llama and Qwen repaired 75% and 86% fewer defects than GPT-4o. Neither fixed any type-propagation or defective-parameter defects.
  • Easy defects are fully solved. Hallucinated skills (which turned out to be misspelled names of real skills) and incorrect outputs were fixed 100% of the time, all at pass@1.
  • Re-synthesizing structure is hard. No model repaired invalid DSL in the simulated set, which fits with known weaknesses of FMs at producing structured output.
  • Returns flatten out. GPT-4o’s repair rate was 27.07% at pass@1 and stopped improving at pass@6 (28.89%), while cost grows linearly with each attempt. We recommend capping repairs at six attempts.

Results on the real-world OpenAGI workflows were better: 34 of 84 defects (40.48%) were repaired, including 100% of defective-parameter defects (up from 31%) and 1 of 8 invalid-DSL defects.

Why this matters

Designing a DSL to be “FM-friendly” shrinks the space of possible mistakes, but it doesn’t eliminate them. On a low-resource DSL, nearly nine out of ten generated workflows contain defects. The practical lesson is to treat the FM as a fallible code generator and wrap it in compiler-style guardrails: parse, validate against the grammar, build a CFG and def-use chains, check against the skill registry, and feed precise diagnostics back to the model. A cheap static analyzer turned a 4.55% self-repair rate into 28.89%, and certain defect types are fixed reliably.

There’s still a lot left to do. Data-flow defects need path-feasibility reasoning, which suggests adding dynamic analysis. Semantic defects such as omitted logic or over-engineering still need a human or an execution oracle. Our next step is to improve Timon with dynamic analysis.

Paper: ACM TOSEM · arXiv preprint · Replication package