Skip to main content

Function: createGuardrailBlockedStream()

createGuardrailBlockedStream(context, evaluation, options?): AsyncGenerator<AgentOSResponse, void, undefined>

Defined in: packages/agentos/src/safety/guardrails/guardrailDispatcher.ts:223

Create a stream that emits a single error chunk for blocked content.

Use this when input evaluation returns GuardrailAction.BLOCK to generate an appropriate error response without invoking orchestration.

Parameters​

context​

GuardrailContext

Guardrail context for the error details

evaluation​

GuardrailEvaluationResult

The blocking evaluation result

options?​

GuardrailOutputOptions

Stream options (streamId, personaId)

Returns​

AsyncGenerator<AgentOSResponse, void, undefined>

Async generator yielding a single ERROR chunk

Example​

if (outcome.evaluation?.action === GuardrailAction.BLOCK) {
yield* createGuardrailBlockedStream(
guardrailContext,
outcome.evaluation,
{ streamId: 'stream-123', personaId: 'support-agent' }
);
return;
}