From d0670f7729c2dd0fd9ce99128f3cc54cad42463c Mon Sep 17 00:00:00 2001 From: Lev Neiman Date: Tue, 7 Apr 2026 11:32:25 -0700 Subject: [PATCH] fix: align condition and template depth limits --- models/src/agent_control_models/controls.py | 6 ++---- models/tests/test_controls.py | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/models/src/agent_control_models/controls.py b/models/src/agent_control_models/controls.py index b9d9de53..6330c67f 100644 --- a/models/src/agent_control_models/controls.py +++ b/models/src/agent_control_models/controls.py @@ -281,8 +281,9 @@ class SteeringContext(BaseModel): type TemplateValue = str | bool | list[str] type JsonValue = JSONValue +MAX_CONDITION_DEPTH = 12 _TEMPLATE_PARAMETER_NAME_RE = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$") -MAX_TEMPLATE_DEFINITION_DEPTH = 12 +MAX_TEMPLATE_DEFINITION_DEPTH = MAX_CONDITION_DEPTH MAX_TEMPLATE_DEFINITION_NODES = 1000 @@ -524,9 +525,6 @@ def normalize_decision(cls, value: str) -> ActionDecision: return normalize_action(value) -MAX_CONDITION_DEPTH = 6 - - def _validate_common_control_constraints( condition: ConditionNode, action: ControlAction, diff --git a/models/tests/test_controls.py b/models/tests/test_controls.py index 6bf07b2c..a9f3a681 100644 --- a/models/tests/test_controls.py +++ b/models/tests/test_controls.py @@ -164,13 +164,28 @@ def test_condition_iter_leaves_preserves_left_to_right_order() -> None: def test_condition_depth_limit_is_enforced() -> None: # Given: a condition tree nested deeper than the allowed maximum + allowed_depth = _leaf("input") + for _ in range(11): + allowed_depth = {"not": allowed_depth} + + control = ControlDefinition.model_validate( + { + "execution": "server", + "scope": {"step_types": ["llm"], "stages": ["pre"]}, + "condition": allowed_depth, + "action": {"decision": "deny"}, + } + ) + + assert control.condition.max_depth() == 12 + too_deep = _leaf("input") - for _ in range(6): + for _ in range(12): too_deep = {"not": too_deep} with pytest.raises( ValidationError, - match="Condition nesting depth exceeds maximum of 6", + match="Condition nesting depth exceeds maximum of 12", ): # When: validating the deep condition tree ControlDefinition.model_validate(