Extracting Logic to utils.ts
Steps are where most of your code lives. Sometimes they start to get complex — lots of data transformation, scoring logic, response parsing. When a step’sfn gets hard to read, you can extract some of that logic into a utils.ts file.
Here’s a step that’s a potential candidate for extraction:
steps.ts
utils.ts
steps.ts
utils.ts:
- Data transformation and normalization
- Scoring algorithms and threshold checks
- Prompt variable formatting
- Response parsing and cleanup
File Organization
Most workflows use a singlesteps.ts file — you can put as many steps as you want in there, and that’s perfectly fine. But sometimes a workflow has steps that naturally group around different concerns: some deal with data fetching, others with enrichment, others with notifications. When that happens, you can split them into a steps/ folder with one file per group.
Single file — the default for most workflows:
steps.ts or any file inside a steps/ directory. The folder approach isn’t about the number of steps; it’s about organizing related steps together so they’re easier to find and reason about.
You can mix patterns across workflows in the same project. One workflow might use
steps.ts while another uses steps/. Output handles both.Shared Steps
When multiple workflows need the same step, put it insrc/shared/steps/. This is common for things like CRM lookups, email verification, or enrichment calls that several workflows depend on.
For example, looking up a contact in HubSpot is something both your lead enrichment and outreach workflows might need:
src/shared/steps/lookup_hubspot_contact.ts
workflow.ts
Evaluators for Flow Control
Evaluators are a special type of step that score LLM output. They use the same@outputai/llm module and follow the same import rules as regular steps. What makes them powerful is using the score to control what happens next — retry if quality is low, skip a step if confidence is high, or branch to a different path.
Here’s an evaluator that judges the quality of an AI-generated company summary:
evaluators.ts
workflow.ts