PipelineSpec provides a fluent API for constructing middleware pipelines that
can be compiled into middleware instances or exported as configuration files.
Quick Example
from pydantic_ai_middleware import PipelineSpec
from pydantic_ai_middleware.builder import MiddlewarePipelineCompiler
# Build a pipeline spec with fluent API
spec = (
PipelineSpec()
.add_type("logging", {"level": "DEBUG"})
.add_type("rate_limit", {"max_requests": 100})
.add_when(
predicate="is_admin",
then=[{"type": "admin_audit"}],
else_=[{"type": "user_audit"}],
)
)
# Export to YAML file
spec.save("middleware-pipeline.yaml")
# Or compile directly to middleware instances
compiler = MiddlewarePipelineCompiler(registry)
middleware_list = spec.compile(compiler)
Supported Node Types
type: A single middleware by registered name
chain: Sequential execution of multiple nodes
parallel: Concurrent execution with result aggregation
when: Conditional branching based on predicates
Export as JSON or YAML
from pydantic_ai_middleware.pipeline_spec import PipelineSpec
PipelineSpec().add_type("logging").save("pipeline.json")
PipelineSpec().add_type("logging").save("pipeline.yaml")
# Or get as string
yaml_str = PipelineSpec().add_type("logging").dump("yaml")
json_str = PipelineSpec().add_type("logging").dump("json")
1---2name: 2522-pipeline-spec-a1346c913description: Pipeline Spec4---5# Pipeline Spec67`PipelineSpec` provides a fluent API for constructing middleware pipelines that8can be compiled into middleware instances or exported as configuration files.910## Quick Example1112```python13from pydantic_ai_middleware import PipelineSpec14from pydantic_ai_middleware.builder import MiddlewarePipelineCompiler1516# Build a pipeline spec with fluent API17spec = (18 PipelineSpec()19 .add_type("logging", {"level": "DEBUG"})20 .add_type("rate_limit", {"max_requests": 100})21 .add_when(22 predicate="is_admin",23 then=[{"type": "admin_audit"}],24 else_=[{"type": "user_audit"}],25 )26)2728# Export to YAML file29spec.save("middleware-pipeline.yaml")3031# Or compile directly to middleware instances32compiler = MiddlewarePipelineCompiler(registry)33middleware_list = spec.compile(compiler)34```3536## Supported Node Types3738- **type**: A single middleware by registered name39- **chain**: Sequential execution of multiple nodes40- **parallel**: Concurrent execution with result aggregation41- **when**: Conditional branching based on predicates4243## Export as JSON or YAML4445```python46from pydantic_ai_middleware.pipeline_spec import PipelineSpec4748PipelineSpec().add_type("logging").save("pipeline.json")49PipelineSpec().add_type("logging").save("pipeline.yaml")5051# Or get as string52yaml_str = PipelineSpec().add_type("logging").dump("yaml")53json_str = PipelineSpec().add_type("logging").dump("json")54```5556## Next Steps5758- [Config Loading](config-loading.md) - Load pipelines from config files59- [API Reference](../api/pipeline_spec.md) - PipelineSpec API
Run npx skillmds@latest add tools-only/2522-pipeline-spec-a1346c91 in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Pipeline Spec It is listed under DevOps & Infra on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tools-only (@tools-only) published this skill. Their other Agent Skills are listed on their SkillMD profile.