Skills Multi-Step Workflow Design
Simple tasks need only one step, but real-world workflows often involve multiple stages.
This article explains how to break complex tasks into clear steps and organize them into a reliable execution flow in SKILL.md.
Why explicitly define steps
Claude is smart, but without clear step guidance, it may skip certain stages or execute them in an inconsistent order.
Benefits of explicit steps:
First, it makes Claude's behavior predictable; second, it helps users understand what is happening; third, it makes it easy to pinpoint which step went wrong when an error occurs.
Basic principles of step design
| Principle | Description |
|---|---|
| Each step does one thing only | Avoid having a single step perform multiple unrelated operations |
| Clear inputs and outputs between steps | The output of one step is the input of the next, with no reliance on implicit state |
| Give feedback after each step | Tell the user what that step accomplished and what comes next |
| Allow mid-way interruption | Users can pause or modify parameters at any step |
Define multi-step workflows in SKILL.md
Example
name: excel-report-generator
description:
Generate a formatted Excel report from user-uploaded raw data, including data cleaning,
chart generation, and summary statistics. Trigger when the user needs a data report, Excel output,
or automated statistics.
Excel Report Generator
Execution flow
Step 1: Read and validate data
1
. Check whether the file exists and whether its format is .csv or .xlsx
2
. Read the file and output basic information:
- Total rows, total columns
- Data type of each column
- Count of null values
3
. If serious problems are found (such as an empty file or unsupported format), stop and tell the user
**
Output
**
: Data basic information report (displayed in the conversation)
Step 2: Data cleaning
Run
`
scripts
/
clean_data.py
`
, execute:
-
Remove completely duplicate rows
-
Fill null values in numeric columns with
0
- Trim leading and trailing whitespace from strings
Output the cleaned data to
`/
home
/
claude
/
cleaned_data.csv
`
**
Output
**
: Cleaning report (how many rows removed, how many values modified)
Step 3: Generate statistical summary
Run
`
scripts
/
calc_stats.py
`
, calculate:
-
The mean, median, and standard deviation of each numeric column
-
Trend data grouped by a time column (if a time column exists)
Output to
`/
home
/
claude
/
stats.json
`
Step 4: Generate the Excel report
Run
`
scripts
/
gen_excel.py
`
, generate an Excel file containing the following:
-
Sheet1: cleaned raw data
-
Sheet2: statistical summary table
-
Sheet3: line chart (if time-series data exists)
Save the final file to
`/
mnt
/
user-data
/
outputs
/
report_YYYYMMDD.xlsx
`
**
Output
**
: call present_files to display the file and provide a download link
Error handling
If any step fails:
1
. Show the complete error message
2
. Explain possible causes
3
. Ask the user whether to skip the current step or retry after modifying parameters
How to organize step scripts
Each step of a multi-step workflow can correspond to a separate script file, or they can be combined into one main script.
Option 1: one script per step (recommended for complex workflows)
excel-report-generator/
├── SKILL.md
└── scripts/
├── clean_data.py # 第二步:数据清洗
├── calc_stats.py # 第三步:统计计算
└── gen_excel.py # 第四步:生成报告
Option 2: a single main script (suitable for simple workflows)
Example
File path: scripts/pipeline.py
A single main script, using the --step parameter to control which step to execute
import
argparse
import
sys
def
step_clean
(
input_file:
str
,
output_file:
str
)
dict
:
"""Step 2: Data cleaning"""
(
f
"Cleaning data: {input_file}"
)
Actual cleaning logic...
return
{
"status"
:
"success"
,
"removed_rows"
:
3
,
"fixed_values"
:
12
}
def
step_stats
(
input_file:
str
,
output_file:
str
)
dict
:
"""Step 3: Statistical calculation"""
(
f
"Calculating statistics: {input_file}"
)
Actual statistical logic...
return
{
"status"
:
"success"
,
"columns_analyzed"
:
5
}
def
step_excel
(
data_file:
str
,
stats_file:
str
,
output_file:
str
)
dict
:
"""Step 4: Generate Excel"""
(
f
"Generating Excel report: {output_file}"
)
Actual generation logic...
return
{
"status"
:
"success"
,
"output"
: output_file
}
STEPS
=
{
"clean"
: step_clean
,
"stats"
: step_stats
,
"excel"
: step_excel
,
}
if
name
==
"main"
:
parser
=
argparse.
ArgumentParser
(
)
parser
.
add_argument
(
"--step"
,
required
=
True
,
choices
=
STEPS.
keys
(
)
,
help
=
"Step to execute: clean / stats / excel"
)
parser
.
add_argument
(
"--input"
,
required
=
True
,
help
=
"Input file path"
)
parser
.
add_argument
(
"--output"
,
required
=
True
,
help
=
"Output file path"
)
args
=
parser
.
parse_args
(
)
import
json
result
=
STEPS
[
args.
step
]
(
args.
input
,
args.
output
)
(
json.
dumps
(
result
,
ensure_ascii
=
False
,
indent
=
2
)
)
Call this script in SKILL.md:
Example
Step 2: Data cleaning
python scripts
/
pipeline.py \
--step
clean \
--input
/
mnt
/
user-data
/
uploads
/
runoob_sales.csv \
--output
/
home
/
claude
/
cleaned_data.csv
Step 3: Statistical calculation
python scripts
/
pipeline.py \
--step
stats \
--input
/
home
/
claude
/
cleaned_data.csv \
--output
/
home
/
claude
/
stats.json
Dependency checks between steps
When a later step depends on output files from earlier steps, check whether the dependency files exist before executing.
Example
File path: scripts/check_deps.py
import
os
import
sys
def
check_step_deps
(
step_name:
str
,
required_files:
list
)
bool
:
"""
Check whether a step's prerequisite files have been generated
Parameters:
step_name: current step name (used in error messages)
required_files: list of file paths that must exist
Returns:
True means all dependencies are ready, False means some files are missing
"""
missing
=
[
f
for
f
in
required_files
if
not
os
.
path
.
exists
(
f
)
]
if
missing:
(
f
"Error: {step_name} is missing prerequisite files:"
)
for
f
in
missing:
(
f
" - {f}"
)
(
"Please complete the prerequisite steps first."
)
return
False
return
True
Usage example: check prerequisite files before generating Excel in step 4
if
name
==
"main"
:
deps
=
[
"/home/claude/cleaned_data.csv"
,
"/home/claude/stats.json"
]
if
not
check_step_deps
(
"Generate Excel report"
,
deps
)
:
sys
.
exit
(
1
)
(
"All prerequisite files are ready, starting to generate the report..."
)
Error: Missing prerequisite file for generating Excel report:
- /home/claude/stats.json
请先完成前置步骤。
In complex workflows, dependencies between steps are easy to overlook. Clear dependency checks can pinpoint the missing link the moment an error occurs, rather than exposing the problem only at the last step.