Streaming
Guard text as it streams from the LLM using StreamingPipeline.
Usage
typescript
import { StreamingPipeline, promptInjection, toxicity } from 'open-guardrail';
const pipeline = new StreamingPipeline({
guards: [
promptInjection({ action: 'block' }),
toxicity({ action: 'block' }),
],
});
// Feed chunks as they arrive
await pipeline.pushChunk('Hello, ');
await pipeline.pushChunk('how can I ');
await pipeline.pushChunk('help you?');
// Finalize and run full-text semantic checks
const result = await pipeline.finish();How It Works
- Chunk-level checks — guards with
supportsStreaming: trueruncheckChunk()on each incoming chunk - Full-text check — on
finish(), all guards runcheck()on the complete accumulated text - Early exit — if a chunk-level check blocks, you can stop streaming immediately
Guards with Streaming Support
Guards that implement checkChunk() can catch issues during streaming:
keyword— matches on each chunkregex— pattern checks per chunkwordCount— running character/word countpii— detects PII patterns in chunks