diff --git a/src/schemas/configuration.py b/src/schemas/configuration.py index 27e2da49..7a3c98bf 100644 --- a/src/schemas/configuration.py +++ b/src/schemas/configuration.py @@ -91,7 +91,10 @@ def _validate_custom_instructions_budget( if not custom_instructions.strip(): return custom_instructions - max_tokens = settings.DERIVER.effective_max_custom_instructions_tokens + max_tokens = settings.DERIVER.MAX_CUSTOM_INSTRUCTIONS_TOKENS + if max_tokens is None: + raise ValueError("custom_instructions are not enabled for this deployment") + if estimate_tokens(custom_instructions) > max_tokens: raise ValueError( f"custom_instructions exceeds DERIVER.MAX_CUSTOM_INSTRUCTIONS_TOKENS ({max_tokens} tokens)" diff --git a/tests/test_schema_validations.py b/tests/test_schema_validations.py index 58016ad9..3bab9ffe 100644 --- a/tests/test_schema_validations.py +++ b/tests/test_schema_validations.py @@ -208,6 +208,25 @@ class TestResolvedConfigurationMigration: class TestReasoningCustomInstructionsValidation: + def test_nonblank_custom_instructions_require_enabled_deployment_cap( + self, monkeypatch: pytest.MonkeyPatch + ) -> None: + monkeypatch.setattr( + settings.DERIVER, "MAX_CUSTOM_INSTRUCTIONS_TOKENS", None, raising=False + ) + + with pytest.raises(ValidationError) as exc_info: + ReasoningConfiguration(custom_instructions="Prefer concrete facts.") + + errors = exc_info.value.errors() + assert any( + error["loc"] == ("custom_instructions",) + and "custom_instructions are not enabled for this deployment" + in error["msg"] + for error in errors + ) + assert "[deriver].MAX_CUSTOM_INSTRUCTIONS_TOKENS" not in str(exc_info.value) + def test_reasoning_configuration_rejects_oversized_custom_instructions( self, monkeypatch: pytest.MonkeyPatch ) -> None: