2121from unplug .config .messages import MessageConfig
2222from unplug .config .policy import MlGateConfig , ScanPolicy
2323from unplug .config .tools import ToolPolicyConfig
24+ from unplug .exceptions import ConfigError
25+
26+ _GUARD_SECTION_KEYS : frozenset [str ] = frozenset (
27+ {
28+ "scanners" ,
29+ "mode" ,
30+ "server_url" ,
31+ "server_api_key" ,
32+ "policy" ,
33+ "cache" ,
34+ "fail_closed" ,
35+ "pipeline" ,
36+ "scanners_config" ,
37+ "limits" ,
38+ "messages" ,
39+ "judge_enabled" ,
40+ "judge_low" ,
41+ "judge_high" ,
42+ "models" ,
43+ "active_model" ,
44+ "auto_download_model" ,
45+ "require_ml" ,
46+ "tools" ,
47+ "boundaries" ,
48+ "trajectory" ,
49+ "intent" ,
50+ "degradation" ,
51+ "toolchain" ,
52+ "collusion" ,
53+ "strict_scanner_allowlist" ,
54+ }
55+ )
56+
57+
58+ def _reject_unknown_guard_keys (data : dict [str , Any ]) -> None :
59+ if "guard" not in data :
60+ return
61+ unknown = sorted (set (data ["guard" ]) - _GUARD_SECTION_KEYS )
62+ if unknown :
63+ msg = f"Unknown [guard] config keys: { ', ' .join (unknown )} "
64+ raise ConfigError (msg )
2465
2566
2667def load_from_file (path : str | Path ) -> dict [str , Any ]:
@@ -218,6 +259,7 @@ def _build_collusion(data: dict[str, Any]) -> CollusionConfig:
218259
219260def build_config (data : dict [str , Any ]) -> GuardConfig :
220261 """Build a GuardConfig from a raw dict (from TOML or env)."""
262+ _reject_unknown_guard_keys (data )
221263 guard_data = data .get ("guard" , data )
222264 kwargs : dict [str , Any ] = {}
223265
@@ -237,6 +279,8 @@ def build_config(data: dict[str, Any]) -> GuardConfig:
237279 )
238280 if "fail_closed" in guard_data :
239281 kwargs ["fail_closed" ] = guard_data ["fail_closed" ]
282+ if "strict_scanner_allowlist" in guard_data :
283+ kwargs ["strict_scanner_allowlist" ] = bool (guard_data ["strict_scanner_allowlist" ])
240284
241285 pipeline_data = guard_data .get ("pipeline" , data .get ("pipeline" , {}))
242286 if pipeline_data :
0 commit comments