vijil_dome.controls:
Installation
The package supports Python 3.11 through 3.13. A
dome:* evaluator can require another optional dependency for its selected Dome Detector.
Choose an API
VijilDome
VijilDome is the recommended policy-driven interface.
Properties
Input Methods
llm Step with text assigned to input, then evaluate the pre stage.
Output Methods
llm Step with text assigned to output, then evaluate the post stage.
Tool Methods
tool Step named tool_name, assign tool_input to input, and evaluate the pre stage.
Instance Decorator
ControlEngine and enforcement setting. See control() for mapping and stage behavior.
Enforcement Behavior
control()
The standalone decorator creates or reuses a ControlEngine and evaluates a function at the pre and post stages.
Passing both
engine and policy raises ValueError. If both are omitted, the decorator uses an empty engine and permits every call.
The wrapper performs these operations:
- Construct a Step from the function arguments.
- Evaluate the
prestage and enforce its result. - Invoke the wrapped function.
- Assign or map the return value to
Step.output. - Evaluate the
poststage and enforce its result. - Return the original function result.
Automatic Input Mapping
Fortool Steps, the decorator maps all bound parameters except self and cls to a dictionary. A tool function with one parameter still receives a dictionary as Step.input.
For llm Steps, the decorator uses the first applicable rule:
- Select
input,message,query,text,prompt,content,user_input,msg, orrequest. - Select the first string-valued argument.
- Use the value directly when one parameter remains.
- Use a dictionary when multiple parameters remain.
- Convert the arguments to a string if signature binding fails or no parameter remains.
input_mapper when these rules do not match your function’s data model.
ControlEngine
ControlEngine loads, stores, and evaluates Controls.
Control objects. Use load_controls() for dictionaries.
Engine Members
Loading more Controls appends them to the existing engine. The loading methods do not replace previously loaded Controls.
Direct engine evaluation returns an
EvaluationResult. It does not raise ControlViolationError or ControlSteerError.
Policy Models
Controls models inherit frompydantic.BaseModel and support standard model validation and serialization.
Step
Step is the runtime payload evaluated by the engine.
Control
Control represents one policy rule.
The model preserves unknown top-level fields during parsing and serialization. Preserved fields are not automatically interpreted by the Controls Engine. Use reverse-DNS keys, such as
example.com/risk-class, for annotation extensions.
ControlScope
Every specified field must match. An omitted field does not restrict the Control. Step-name regular expressions use RE2 when
google-re2 is installed and otherwise use Python’s standard regular-expression engine with a warning.
EvaluatorRef
ConditionNode
A leaf node requires both selector and evaluator:
Leaf and composite fields are mutually exclusive. A leaf with only a selector or only an evaluator fails validation. Empty
and and or lists also fail validation.
is_leaf() reports whether the node contains leaf fields. is_composite() reports whether the node contains a logical operator.
ControlAction
Always supply
steering_context for a steer action. Without it, the engine can return steer, but the interface logs a warning and does not raise ControlSteerError.
SteeringContext
Results
EvaluationResult
An
observe action does not appear as an aggregate action. The observation appears as a triggered entry in matches and does not change the aggregate action. If no deny or steer Control triggers, the result is allow.
The current engine reduces conditions to truth values before constructing ControlMatch. A completed Control evaluation therefore reports confidence 1.0, while an evaluation error reports 0.0. The engine does not propagate EvaluatorResult.confidence to ControlMatch or EvaluationResult.
ControlMatch
A fail-open error produces a non-triggered match without an action. A fail-closed error produces a triggered match with the Control action.
Evaluator API
Evaluator
Custom evaluators subclass the abstract Evaluator class:
value is the selector result. config is the dictionary from EvaluatorRef.config.
EvaluatorResult
Pydantic validation rejects confidence values outside the inclusive 0.0 through 1.0 range.
Registry Functions
register_evaluator() raises TypeError if the decorated class does not subclass Evaluator. resolve_evaluator() raises ValueError for an unknown or unsupported name. Dynamic dome:* references do not appear in list_evaluators().
Built-In Evaluators
regex
Converts the selected value to text and searches one or more regular expressions.
If no pattern is supplied, the evaluator returns
matched=False. RE2 is used when installed. A pattern with flags uses Python’s standard engine because the RE2 package does not expose compatible flag behavior.
list
Converts the selected value to text and compares it with configured strings.
If
values is empty, the evaluator returns matched=False. When supplied, match_on takes precedence over negate.
json_schema
Validates the selected value with the jsonschema package from the controls-full extra.
field_constraints supports type, min, max, enum, min_length, and max_length. Every configured field becomes required.
An invalid schema returns matched=False, confidence 0.0, and schema error metadata. It does not raise into the Control’s on_error behavior.
cel
Evaluates a Common Expression Language expression with cel-python from the controls-full extra.
The selected value is available as
value. When the value is a dictionary, each top-level string key except value is also available as a variable. The reserved value variable always refers to the complete selected value.
A missing or invalid expression returns matched=False. An evaluation error returns confidence 0.0 and error metadata rather than raising into on_error.
dome:<detector-name>
Prefix a registered Dome Detector with dome: to use it as an Evaluator:
The Evaluator converts the selected value to a
DomePayload. Matching uses score >= threshold; Evaluator metadata retains the Detector’s hit value, but that value does not override the configured threshold. The result metadata includes the Detector name, score, hit, and full Detector details.
See Detection Methods for available Detectors and their dependencies.
Selector Utilities
resolve()
resolve() applies a supported selector path to a Step. It reads dictionary keys and object attributes, supports non-negative list indexes, and returns MISSING when the path cannot be resolved.
MISSING
MISSING is the singleton sentinel returned for an unresolved selector. It evaluates to False and remains distinct from valid values such as 0, False, "", and []. The engine evaluates these valid values and skips only MISSING.
Errors
ControlError
ControlViolationError
Subclass of ControlError raised by VijilDome or @control() when an enforced deny result occurs. It adds no attributes.
ControlSteerError
ControlError raised for an enforced steer result with correction guidance. Its steering_context attribute contains that guidance.
Policy validation errors and unknown Evaluator resolution errors are not ControlError subclasses. The engine captures raised condition errors in ControlMatch.error and applies on_error.
Evaluation Semantics
The engine applies these observable rules:- Copy the current Controls and skip disabled or out-of-scope entries.
- Evaluate applicable
denyControls beforesteerandobserveControls. - Return
denyas soon as a deny Control triggers and cancel outstanding Control evaluations. - If no deny triggers, evaluate
steerandobserveControls. - Return the first triggered
steermatch or otherwise returnallow.
priority order. Deny Controls run concurrently, so priority does not guarantee which simultaneous deny result finishes and returns first. A deny result also prevents applicable steer and observe Controls from running.
and and or children run concurrently by default. Set early_exit=True to run their children sequentially and short-circuit. not inverts its child result.
on_error=fail_closed is the default. A raised evaluator error triggers the Control and associates its action with the match. on_error=fail_open records a non-triggered match and allows evaluation to continue. Evaluators that convert their own errors into matched=False do not activate on_error.
Policy Files
JSON And YAML
JSON and YAML accept a flat list:controls key:
controls or controls-full extra.
TOML
Native TOML uses an array of Control tables:[guardrail] configuration and translates its configured Guards into Controls. Files with another extension raise ValueError.
AgentControl Compatibility
The Controls Engine accepts common AgentControl policy shapes without importing AgentControl.
The following AgentControl Evaluators are not included:
Resolving one of these names raises a descriptive
ValueError. The containing Control then applies its configured on_error behavior.
Next Steps
Controls Engine
Apply Controls to LLM inputs, outputs, and tool calls
Detection Methods
Review Detectors available through the
dome: prefix