Independent Auditing of AI Agents. Run by human or the agent itself, to answer the most crucial question in the AI Agent Economy. Is the agent doing what is supposed to do? With iFixAi you can have this answer in less than 120 seconds.
Python agent-evaluationaiai-alignmentai-evaluationai-governanceai-safetyclidiagnostic-tooleu-ai-acthallucination-detectioniso-42001llm-evaluationllm-securitynist-ai-rmfowasp-llmprompt-injectionpythonresponsible-airisk-assessmentrisk-management
fix: reject ambiguous rule definition identifiers (#263)
Rudy Mizrahi Celeklie29757c96bcf
diff --git a/ifixai/rules/loader.py b/ifixai/rules/loader.pyindex c7e5a42..41adf2d 100644--- a/ifixai/rules/loader.py+++ b/ifixai/rules/loader.py@@ -37,6 +37,8 @@ class RuleLoader:for yaml_path in sorted(self.rules_dir.glob("b*/definition.yaml")):raw = self._read_yaml(yaml_path)bid = raw.get("test_id", yaml_path.parent.name)+ if bid in plans:+ raise RuleLoadError(f"Duplicate rule definition test_id: {bid}")plans[bid] = self._parse_plan(raw, bid)return plans@@ -47,10 +49,10 @@ class RuleLoader:short_id = test_id.replace("SSCI-", "").lower()- for yaml_path in self.rules_dir.glob(f"{short_id}_*/definition.yaml"):- return yaml_path-- return None+ matches = sorted(self.rules_dir.glob(f"{short_id}_*/definition.yaml"))+ if len(matches) > 1:+ raise RuleLoadError(f"Ambiguous rule definition for {test_id}: {matches}")+ return matches[0] if matches else Nonedef _read_yaml(self, path: Path) -> dict[str, Any]:try:diff --git a/ifixai/tests/test_rule_loader_ambiguous_ids.py b/ifixai/tests/test_rule_loader_ambiguous_ids.pynew file mode 100644index 0000000..a4720fc--- /dev/null+++ b/ifixai/tests/test_rule_loader_ambiguous_ids.py@@ -0,0 +1,25 @@+import pytest+import yaml++from ifixai.rules.loader import RuleLoader, RuleLoadError+++def loader(tmp_path):+ for suffix in ["first", "second"]:+ folder = tmp_path / f"b05_{suffix}"+ folder.mkdir()+ (folder / "definition.yaml").write_text(+ yaml.safe_dump({"test_id": "B05", "steps": [{"prompt_template": suffix}]})+ )+ return RuleLoader(tmp_path)+++def test_individual_loading_rejects_ambiguous_directory_id(loader):+ with pytest.raises(RuleLoadError, match="Ambiguous"):+ loader.load_rules("B05")+++def test_bulk_loading_rejects_duplicate_declared_id(loader):+ with pytest.raises(RuleLoadError, match="Duplicate"):+ loader.load_all_rules()