Skip to content

API Reference parrot.bots.flows.plan.guards

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.bots.flows.plan.guards

View source

CEL guards for ExecutionPlan nodes.

PlanNode.when reuses the CEL evaluator the flow package already ships (parrot.bots.flows.flow.cel_evaluator.CELPredicateEvaluator) rather than introducing a second predicate language. CEL is sandboxed, has no arbitrary code execution, and compiles at construction time — which is exactly what a fail-fast plan validator needs.

Activation

A guard sees only cheap, structural values:

ctx.artifacts.<node_id>.<facet> Facets published by upstream nodes. ctx.status.<node_id> "ok" | "skipped" | "partial" | "error". ctx.errors Number of failed nodes so far.

There is deliberately no way to reach a payload body from a guard: branching must stay free.

Examples::

ctx.artifacts.triage.critical > 0
ctx.artifacts.listing.n_reports > 0 && ctx.errors == 0
ctx.status.fetch_reports == "ok"

Class GuardCompilationError

Raised when a when expression fails to compile.

Class PlanGuard

A compiled when expression.

Compilation happens in __init__ so an invalid guard is caught during plan validation — before a single tool runs — rather than mid-flight.

Parameter Type Default Description
expression str The CEL expression.

Method PlanGuard.evaluate

Evaluate the guard against the accumulated facet map.

Evaluation is fail-safe in the underlying evaluator: a runtime error yields False. That is the right default here — an unevaluable guard skips its node rather than running it on unknown state — but it does mean a typo in a facet name reads as "condition not met", so the validator warns about facets no node publishes.

evaluate(artifacts: Mapping[str, Mapping[str, Any]], statuses: Optional[Mapping[str, str]] = None, errors: int = 0, extra: Optional[Mapping[str, Any]] = None) -> bool

Parameter Type Default Description
artifacts Mapping[str, Mapping[str, Any]] {node_id: {facet: value}} published so far.
statuses Optional[Mapping[str, str]] None {node_id: status} for completed nodes.
errors int 0 Count of failed nodes so far.
extra Optional[Mapping[str, Any]] None Additional activation keys (e.g. proposal for delegate accept_when).

Returns: bool — True when the node should run.

Function compile_guard

Compile expression into a :class:PlanGuard, or None.

compile_guard(expression: Optional[str]) -> Optional[PlanGuard]

Parameter Type Default Description
expression Optional[str] A CEL expression, or None for an unguarded node.

Returns: Optional[PlanGuard] — The compiled guard, or None when no expression was given.

Raises:

  • GuardCompilationError — If the expression does not compile.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally