Skip to content
Back to skills

2902 Chain 02e6ae60

ASecurity

Compose multiple middleware into a reusable, ordered sequence. `MiddlewareChain` groups middleware together so they can be managed as a single unit. Chains can be nested, combined with `+`, and modified dynamically.

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
developmentpythonapisecurity

Works with

  • api

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 2902-chain_02e6ae60 --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 2902 Chain 02e6ae60?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 2902 Chain 02e6ae60
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-2902-chain-02e6ae60/badge)](https://www.skillsdirectory.com/skills/tools-only-2902-chain-02e6ae60)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# MiddlewareChain

Compose multiple middleware into a reusable, ordered sequence.

`MiddlewareChain` groups middleware together so they can be managed as a single
unit. Chains can be nested, combined with `+`, and modified dynamically.

## Quick Example

```python
from pydantic_ai_middleware import MiddlewareChain, MiddlewareAgent

# Create reusable middleware chains
security_chain = MiddlewareChain([
    AuthMiddleware(),
    RateLimitMiddleware(),
], name="security")

logging_chain = MiddlewareChain([
    RequestLogMiddleware(),
    ResponseLogMiddleware(),
], name="logging")

# Combine chains
full_chain = security_chain + logging_chain

# Or build incrementally
chain = MiddlewareChain(name="my-chain")
chain.add(AuthMiddleware())
chain.add(LoggingMiddleware())

# Use with an agent
agent = MiddlewareAgent(
    agent=base_agent,
    middleware=[full_chain],
)
```

## API Reference

::: pydantic_ai_middleware.MiddlewareChain
    options:
      show_source: true
      members:
        - __init__
        - name
        - middleware
        - add
        - insert
        - remove
        - pop
        - replace
        - clear
        - copy
        - before_run
        - after_run
        - before_model_request
        - before_tool_call
        - after_tool_call
        - on_error

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.