Skip to content

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.

fix: reject empty and nonstring phrasing probes (#237)

Rudy Mizrahi Celekli9c3cbf3f9fa2
diff --git a/ifixai/harness/prompt_pool.py b/ifixai/harness/prompt_pool.py
index 005aaff..1908f54 100644
--- a/ifixai/harness/prompt_pool.py
+++ b/ifixai/harness/prompt_pool.py
@@ -55,6 +55,10 @@ def load_phrasing_pool(path: Path) -> list[PhrasingGroup]:
raise PromptPoolError(
f"{path}: group {gid!r} must have a 'phrasings' list with at least 2 entries"
)
+ if any(not isinstance(text, str) or not text.strip() for text in phrasings):
+ raise PromptPoolError(
+ f"{path}: group {gid!r} phrasings must be nonempty strings"
+ )
if gid in seen_ids:
raise PromptPoolError(f"{path}: duplicate group id {gid!r}")
seen_ids.add(gid)
diff --git a/ifixai/tests/test_phrasing_pool_validation.py b/ifixai/tests/test_phrasing_pool_validation.py
new file mode 100644
index 0000000..f40944e
--- /dev/null
+++ b/ifixai/tests/test_phrasing_pool_validation.py
@@ -0,0 +1,29 @@
+import pytest
+import yaml
+
+from ifixai.harness.prompt_pool import PromptPoolError, load_phrasing_pool
+
+
+ "phrasings", [["hello", ""], ["hello", " "], ["hello", None], ["hello", 12]]
+)
+def test_invalid_phrasings_raise_pool_error(tmp_path, phrasings):
+ path = tmp_path / "pool.yaml"
+ path.write_text(
+ yaml.safe_dump(
+ {"groups": [{"id": "g", "category": "c", "phrasings": phrasings}]}
+ )
+ )
+ with pytest.raises(PromptPoolError, match="phrasing"):
+ load_phrasing_pool(path)
+
+
+def test_valid_phrasings_preserve_original_text(tmp_path):
+ path = tmp_path / "pool.yaml"
+ phrasings = ["Hello?", " Hi there? "]
+ path.write_text(
+ yaml.safe_dump(
+ {"groups": [{"id": "g", "category": "c", "phrasings": phrasings}]}
+ )
+ )
+ assert load_phrasing_pool(path)[0].phrasings == phrasings