Skip to content

armgit / laya

Public Imported from GitHub
0

Non-autoregressive System 1 decision engine. Typed choice, score and yes/no decisions over any text in a single forward pass, in 100+ languages, with a router that picks the right checkpoint per request.

fix(agent): reject a null score level

Rishit Sharma67edd5fcf676
diff --git a/laya/agent.py b/laya/agent.py
index b0fb78a7..43e33ef6 100644
--- a/laya/agent.py
+++ b/laya/agent.py
@@ -505,6 +505,9 @@ class Agent(HookRegistry):
"descriptions, index 0 first" % (qid,))
if not crit:
raise ValueError("question %r: a score question needs at least one level" % (qid,))
+ if None in crit:
+ raise ValueError("question %r: score level %d is null; give every level a description, "
+ "index 0 first" % (qid, crit.index(None)))
elif crit is not None and not isinstance(crit, dict):
raise ValueError("question %r: a noul question takes 'criteria' as a dict with optional "
"'true'/'false' descriptions, or omits it" % (qid,))
diff --git a/tests/test_criteria.py b/tests/test_criteria.py
index 738ea87f..84199cde 100644
--- a/tests/test_criteria.py
+++ b/tests/test_criteria.py
@@ -272,6 +272,10 @@ for label, qdef in [
("score with an empty list", {"type": "score", "instructions": "How urgent?", "criteria": []}),
("score with a dict of levels", {"type": "score", "instructions": "How urgent?",
"criteria": {"low": "no pressure", "high": "blocking"}}),
+ # a null level reached the model as the text "level 1: null" and came back as a null legend
+ # value, which a Jev client refuses to parse (#302)
+ ("score with a null level", {"type": "score", "instructions": "How urgent?",
+ "criteria": ["low", None, "high"]}),
("choice with labels", {"type": "choice", "instructions": "Which team?",
"criteria": ["billing", "tech"],
"labels": {"false": "B", "true": "A"}}),
@@ -311,6 +315,12 @@ for label, qdef in [
except Exception as e:
FAIL.append("rejected/%s: %s instead of ValueError: %s" % (label, type(e).__name__, e))
+try:
+ agent.system_one(STATE, {"q": {"type": "score", "instructions": "How urgent?", "criteria": ["low", None]}})
+ FAIL.append("rejected/score null level names the level: no error raised")
+except ValueError as e:
+ check_true("rejected/score null level names the level", "level 1" in str(e), str(e))
+
# the same questions through the public entry point, not only the method under it
router = Router()
router.attach("english", agent)
diff --git a/tests/test_server_example.py b/tests/test_server_example.py
index 3f8a75f4..9bb6c7e0 100644
--- a/tests/test_server_example.py
+++ b/tests/test_server_example.py
@@ -96,6 +96,10 @@ def main():
ok("POST /predict rejects choice with no criteria as 422, not 500", r.status_code == 422, str(r.status_code))
r = client.post("/predict", json={"state": "hi", "questions": {"x": {"type": "score", "instructions": "?"}}})
ok("POST /predict rejects score with no criteria as 422, not 500", r.status_code == 422, str(r.status_code))
+ # a null level used to be scored as the text "level 1: null" and echoed back in the legend (#302)
+ r = client.post("/predict", json={"state": "hi", "questions": {"x": {
+ "type": "score", "instructions": "?", "criteria": ["low", None, "high"]}}})
+ ok("POST /predict rejects a null score level as 422", r.status_code == 422, str(r.status_code) + " " + r.text[:200])
# /gui is the form-post path the builder JS uses -- this is what caught the
# missing python-multipart dependency during manual verification.