Engine

Evaluate one guardrail against a payload.

GuardrailEngine runs a guardrail’s strategy on each text segment of a payload, and returns a GuardrailOutcome with a finding for each segment that triggered. It knows nothing of actions or events: GuardrailPipeline runs the engine and the actions, one guardrail at a time, so that each guardrail sees the payload as changed by the guardrails before it.

class smarter.apps.guardrail.services.engine.GuardrailEngine[source]

Bases: object

Evaluate guardrails against payloads.

Stateless.

evaluate(guardrail, payload, stage, context)[source]

Evaluate one guardrail against every text segment of the payload.

Any exception raised by the strategy is recorded in the outcome’s error, rather than raised, so that one failing guardrail cannot take down the prompt.

Parameters:
  • guardrail (Guardrail) – The guardrail.

  • payload (dict[str, Any]) – The chat completion request (pre stage) or response (post stage).

  • stage (GuardrailStage) – Which side of the model call the payload is.

  • context (StrategyContext) – Ambient evaluation context.

Return type:

GuardrailOutcome

Returns:

The outcome, with a finding for each segment that triggered.