Skip to content

GuardrailStream

Stateful guardrail filter for one streamed LLM response.

Defined in: src/core/pipeline/GuardrailPipeline.ts:315

Stateful guardrail filter for one streamed LLM response.

Remarks

In 'streaming' mode the stream accumulates chunks until a segment boundary, runs the 'chunk' stage over each completed segment, and forwards survivors to the sink immediately. In 'buffered' mode nothing is forwarded until GuardrailStream.flush, which runs the 'final' stage over the whole response — slower to first audio, but a block is absolute.

Once a guardrail blocks, the stream stays blocked for the rest of the utterance: text already handed to the TTS provider cannot be recalled, so the only remaining option is to stop feeding it.

See

GuardrailPipeline.createStream

Constructors

Constructor

new GuardrailStream(
   pipeline, 
   settings, 
   options): GuardrailStream;

Defined in: src/core/pipeline/GuardrailPipeline.ts:331

Internal

Constructed via GuardrailPipeline.createStream.

Parameters

ParameterType
pipelineGuardrailPipeline
settingsRequired<Omit<GuardrailsConfig, "filters">>
optionsGuardrailStreamOptions

Returns

GuardrailStream

Accessors

isBlocked

Get Signature

get isBlocked(): boolean;

Defined in: src/core/pipeline/GuardrailPipeline.ts:338

Whether a guardrail has suppressed the remainder of this utterance.

Returns

boolean


spokenText

Get Signature

get spokenText(): string;

Defined in: src/core/pipeline/GuardrailPipeline.ts:343

Text forwarded to the sink so far.

Returns

string

Methods

flush()

flush(): Promise<string>;

Defined in: src/core/pipeline/GuardrailPipeline.ts:410

Filter and forward whatever text remains, ending the utterance.

Returns

Promise<string>

The full text that was forwarded to the sink for this utterance.

Remarks

In 'buffered' mode this is where the entire response is filtered and emitted, at the 'final' stage. In 'streaming' mode the only text left is the tail of the last sentence, and it is filtered at the 'chunk' stage like every segment before it — so a guardrail restricted to ['final'] does not run on the streaming path at all. Call once, after the LLM stream completes and before finalizing the TTS provider. Safe to call when nothing is buffered.


push()

push(raw): Promise<void>;

Defined in: src/core/pipeline/GuardrailPipeline.ts:371

Feed one raw LLM chunk.

Parameters

ParameterType
rawstring

Returns

Promise<void>

Remarks

Resolves once every segment the chunk completed has been filtered and handed to the sink. Awaiting keeps text in order and lets a backpressured sink throttle the LLM loop.


reset()

reset(): void;

Defined in: src/core/pipeline/GuardrailPipeline.ts:434

Discard all buffered state.

Returns

void

Remarks

Call when a turn is abandoned (barge-in, abort) so the next utterance starts clean. Does not un-block a stream that was already blocked; create a new stream per utterance instead.


takeSpokenText()

takeSpokenText(): string;

Defined in: src/core/pipeline/GuardrailPipeline.ts:357

Text forwarded to the sink since the last call, marking it as reported.

Returns

string

Remarks

The caller finalizing a TTS provider needs the text of that utterance, not of the whole stream. A tool loop shares one stream across rounds and finalizes at each tool boundary, so reading spokenText there would repeat everything spoken in earlier rounds. Returns '' once a guardrail has blocked and nothing further reached the provider.

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency