Skip to content

Commit 03f402e

Browse files
authored
feat(server): Align condition and template depth limits (#166)
## Summary - increase the shared condition nesting depth limit from 6 to 12 - make `MAX_TEMPLATE_DEFINITION_DEPTH` derive from `MAX_CONDITION_DEPTH` so both limits stay aligned - expand the condition-depth model test to verify depth 12 succeeds and depth 13 still fails ## Why The condition-tree limit had been raised independently, but the template definition depth used a separate constant value. Referencing the shared constant removes drift and keeps template-backed controls aligned with the same supported nesting depth. ## Impact Template-backed and non-template control validation now share one source of truth for depth limits. Future changes to the condition limit will automatically apply to template definition depth as well. ## Validation - `make test TEST= models/tests/test_controls.py` (this invoked the repo's full default `make test` chain and passed across models, telemetry, server, engine, Python SDK, and builtin evaluators) - `make models-test`
1 parent d7f309a commit 03f402e

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

models/src/agent_control_models/controls.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,9 @@ class SteeringContext(BaseModel):
281281
type TemplateValue = str | bool | list[str]
282282
type JsonValue = JSONValue
283283

284+
MAX_CONDITION_DEPTH = 12
284285
_TEMPLATE_PARAMETER_NAME_RE = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$")
285-
MAX_TEMPLATE_DEFINITION_DEPTH = 12
286+
MAX_TEMPLATE_DEFINITION_DEPTH = MAX_CONDITION_DEPTH
286287
MAX_TEMPLATE_DEFINITION_NODES = 1000
287288

288289

@@ -524,9 +525,6 @@ def validate_decision(cls, value: str) -> ActionDecision:
524525
return validate_action(value)
525526

526527

527-
MAX_CONDITION_DEPTH = 6
528-
529-
530528
def _validate_common_control_constraints(
531529
condition: ConditionNode,
532530
action: ControlAction,

models/tests/test_controls.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,28 @@ def test_condition_iter_leaves_preserves_left_to_right_order() -> None:
164164

165165
def test_condition_depth_limit_is_enforced() -> None:
166166
# Given: a condition tree nested deeper than the allowed maximum
167+
allowed_depth = _leaf("input")
168+
for _ in range(11):
169+
allowed_depth = {"not": allowed_depth}
170+
171+
control = ControlDefinition.model_validate(
172+
{
173+
"execution": "server",
174+
"scope": {"step_types": ["llm"], "stages": ["pre"]},
175+
"condition": allowed_depth,
176+
"action": {"decision": "deny"},
177+
}
178+
)
179+
180+
assert control.condition.max_depth() == 12
181+
167182
too_deep = _leaf("input")
168-
for _ in range(6):
183+
for _ in range(12):
169184
too_deep = {"not": too_deep}
170185

171186
with pytest.raises(
172187
ValidationError,
173-
match="Condition nesting depth exceeds maximum of 6",
188+
match="Condition nesting depth exceeds maximum of 12",
174189
):
175190
# When: validating the deep condition tree
176191
ControlDefinition.model_validate(

0 commit comments

Comments
 (0)