Skip to main content

pipecat-guardrails

Output guardrails for Pipecat voice agents. It checks what your bot is about to say, and stops it before it is spoken.

Status: early development. Built: the rule layer (banned terms, regex, personal data, India pack), guard.check(), and the Pipecat processor. Next: the classifier and LLM-judge layers. See PLAN.md.

In a Pipecat pipeline

Put OutputGuardProcessor between the LLM and the TTS. That is the only change to your bot.

from pipecat_guardrails import Guard
from pipecat_guardrails.pipecat import OutputGuardProcessor
from pipecat_guardrails.rules import PII, BannedTerms, pii

guard = Guard(
    rules=[
        BannedTerms(["acme corp"], id="no-competitors"),
        PII(pii.email(), pii.phone(), id="pii"),
    ],
    fallback="Sorry, I can only help with our own products.",
)

pipeline = Pipeline([
    transport.input(), stt, context_aggregator.user(), llm,
    OutputGuardProcessor(guard),   # checks each sentence before it is spoken
    tts, transport.output(), context_aggregator.assistant(),
])
  • Each sentence is checked before the TTS gets it, so nothing unchecked is spoken.
  • On a block, the rest of the reply is dropped and the fallback is spoken instead. Blocked text never reaches the TTS, so it never enters the conversation history either.
  • User interruptions, function calls and lines your own code speaks (TTSSpeakFrame) are handled and pass through in order.
  • OutputGuardProcessor(guard, strategy="full_reply") checks the whole reply before speaking any of it: safer for rules that need the full reply, at the cost of latency.
  • Events: @processor.event_handler("on_violation") and "on_check".

Using RTVI (a Pipecat client SDK)? By default Pipecat sends every LLM token to the client app before the guard checks it. Pass rtvi_observer_params=guarded_rtvi_observer_params() (from pipecat_guardrails.pipecat) to PipelineWorker to turn that off.

Try it without API keys: uv run python examples/pipeline_demo.py. A full voice bot is in examples/pipecat_bot.py.

Without Pipecat's LLM loop

If your app runs its own LLM loop, check whole replies directly. Everything is opt-in: the guard only runs the rules you give it.

from pipecat_guardrails import Guard
from pipecat_guardrails.packs import india
from pipecat_guardrails.rules import PII, BannedTerms, pii

guard = Guard(
    rules=[
        BannedTerms(["acme corp", "globex"], id="no-competitors"),
        BannedTerms(
            ["dawai band kar do", "chinta mat"],
            id="no-medical-advice",
            word_pattern=india.hinglish_word_pattern,   # also matches "davai", "cheenta", ...
            variants={"dawai": ["दवाई"]},
        ),
        PII(pii.email(), pii.card(), india.aadhaar(), india.phone(), id="pii"),  # redacts
    ],
    fallback="Sorry, I can't help with that.",
)

verdict = await guard.check("Aap davaai band kar do.")
verdict.blocked     # True
verdict.text        # "Sorry, I can't help with that."
verdict.rule_ids    # ("no-medical-advice",)
  • Actions: each rule can block (speak the fallback instead), redact (replace the match, e.g. [phone number]), or flag (report only).
  • Opt out: pass enabled=False to a rule, or call guard.disable("pii") at runtime.
  • Shadow mode: Guard(..., mode="shadow") reports what it would do without changing anything, so you can try new rules on live traffic.
  • Errors: a rule that crashes fails closed (blocks) by default. Use on_error="allow" to fail open instead.
  • Custom rules: any function works:
    @rule(id="no-urls")
    def no_urls(text: str) -> bool:
        return "http" in text
    

Runnable examples, the same health bot in two languages: examples/whole_reply_english.py and examples/whole_reply_hinglish.py.

Why

Pipecat has no built-in output guardrail, so every team writes its own processor between the LLM and the TTS. These homemade processors tend to break on user interruptions, keep speaking after a violation, let blocked text into the LLM history, and miss paraphrases and Hindi/Hinglish text.

See BEFORE_AFTER.md for a side-by-side comparison and PLAN.md for the design and roadmap.

Install

pip install pipecat-guardrails          # includes Pipecat
pip install "pipecat-guardrails[jev]"   # also installs the TypeSafe Jev classifier client

Requires Python 3.11+ and Pipecat 1.12 or later (installed automatically).

How checking works

Each sentence goes through up to three layers, and stops at the first one that is sure:

  1. Banned words, PII, regex: local and instant.
  2. Classifier model (optional), such as TypeSafe Jev: a fast yes/no model with an API key. A confident answer decides; an unsure one moves to layer 3.
  3. LLM judge (optional): any OpenAI-compatible LLM gives the final answer.

Layers 2 and 3 use Pipecat's own classifiers (pipecat.classifiers), so any classifier Pipecat supports works here.

Development

uv sync                      # create .venv with dev tools
uv run pytest                # tests
uv run ruff check .          # lint
uv run ruff format .         # format
uv run pyright               # type check
uv run pre-commit install    # run the checks on every commit

License

BSD-2-Clause, the same as Pipecat.

Metadata

Release files for pipecat-guardrails 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pipecat-guardrails 0.2.1
File Size Uploaded Provenance Actions
pipecat_guardrails-0.2.1.tar.gz 35.6 kB With provenance Details for pipecat_guardrails-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pipecat-guardrails 0.2.1
File Interpreter ABI Platform Actions
pipecat_guardrails-0.2.1-py3-none-any.whl Python 3 none any Details for pipecat_guardrails-0.2.1-py3-none-any.whl

Total release size: 67.9 kB

Release files / pipecat_guardrails-0.2.1.tar.gz

Download URL pipecat_guardrails-0.2.1.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b800ab6562025534c50bd12ddeb92ab6c74f5693b5e1f3b27aa8742a8798ce35
BLAKE2b-256 checksum
How to use checksums
6475aeaa5147142281eefab3e7813dc04f0a400e1ffd36f3aa8661e7ae622486
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / pipecat_guardrails-0.2.1-py3-none-any.whl

Download URL pipecat_guardrails-0.2.1-py3-none-any.whl
Size 32.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64caf33a6b5cfa9433f3a2a696deb100e817a8702a454a60fa6babb7618dc135
BLAKE2b-256 checksum
How to use checksums
0995f9e406dabe8d62d0b5bc6f6e339000f315d94ac906e31cb038be5067f722
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Security for pipecat-guardrails 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pipecat_guardrails-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page