Skip to main content
Community-maintained integration. This service is built and maintained by Apoorv012. Pipecat does not test or officially support it. Please report issues and request changes on the source repository. Learn more about community integrations.

Overview

OutputGuardProcessor sits between the LLM and the TTS and checks what the bot is about to say. Each sentence is checked before the TTS gets it, so nothing unchecked is spoken. A sentence can be allowed, redacted (for example a phone number becomes [phone number]), or blocked: on a block, the rest of the reply is dropped and a fallback line 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) pass through in order. A Guard decides what is allowed, in up to three layers, stopping at the first one that is sure:
  1. Rules: banned terms, regular expressions, and personal data (email, phone, card numbers, plus an India pack for Aadhaar, PAN, and Hinglish word lists). Local and instant.
  2. Classifier (optional): any Pipecat classifier, such as Jev, answers yes/no policies about the reply in one call.
  3. Judge (optional): an LLM, through Pipecat’s LLM classifier, decides the policies the classifier was unsure about.

Source Repository

Source code, examples, and issues for Pipecat Guardrails

PyPI Package

The pipecat-guardrails package on PyPI

Installation

This is a community-maintained package distributed separately from pipecat-ai:
To use the Jev classifier for policies:

Prerequisites

  • Pipecat 1.12.0 or later: pipecat-ai>=1.12,<2
  • Python 3.11 or later
  • No API key for rules. Rules run locally.
  • For policies, the keys of the classifier or judge you choose, for example TYPESAFE_API_KEY for Jev, or your LLM provider’s key for a judge.

Configuration

OutputGuardProcessor

Guard
required
The guard that checks each sentence (or the whole reply).
str
default:"sentence"
"sentence" checks each sentence before it is spoken. "full_reply" holds the whole reply, checks it once, then speaks it: safer for rules that need the full reply, at the cost of latency.
int
default:"5"
With the "sentence" strategy, how many sentences are checked at once. Sentences are always released in order, so usually only the first sentence of a reply waits for a classifier or judge round trip.
Events: on_violation(processor, verdict) when a rule or policy fires, and on_check(processor, verdict) for every check.

Guard

Iterable[Rule]
default:"()"
Layer 1: BannedTerms, Regex, PII, or any function decorated with @rule. Each rule can block, redact, or flag.
Mapping[str, str | Policy]
default:"None"
Yes/no questions about the reply, by id, where “yes” means it breaks the policy. Needs a classifier, a judge, or both.
BaseClassifier
default:"None"
Layer 2: a Pipecat classifier that answers every policy in one call.
BaseClassifier
default:"None"
Layer 3: usually LLMClassifier, for the policies the classifier was unsure about.
str | Callable
default:"None"
What to say instead of blocked text, or a function of the verdict. None says nothing.
str
default:"enforce"
"shadow" reports what the guard would do without changing anything, so new rules can be tried on live traffic.
str
default:"block"
What a failed or timed-out check does: "block" (fail closed) or "allow" (fail open).
See the source repository for the full list of options, policies, and the pipecat-guardrails eval command for measuring a guard on your own data.

Usage

Put OutputGuardProcessor between the LLM and the TTS:
Add policies for what word lists miss, such as paraphrases:

Compatibility

Tested with Pipecat v1.16.0. Check the source repository for the latest tested version and changelog.