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.
Python calibrationclassificationdecision-modelhuggingfacejevmodernbertmultilingualnlppythonpytorchroutingtyped-decisionszero-shot
fix(integrations): a remote answers field that is not an object raises, not leaks
Aashishe4bbb1204468
diff --git a/laya/integrations/agno.py b/laya/integrations/agno.pyindex 20dc6cc5..13dd4e4b 100644--- a/laya/integrations/agno.py+++ b/laya/integrations/agno.py@@ -331,6 +331,16 @@ def _call_remote(f"Malformed decision response from Laya server at {url}: "f"expected a JSON object, got {type(parsed).__name__}")+ # `parsed` is an object now, but its `answers` field is the same arbitrary JSON: a gateway can+ # answer `{"answers": []}`. Both consumers read it as `res.get("answers", {})` and then call+ # `.get("delegation", …)` / `.items()` on it, so a non-object there leaks AttributeError past the+ # same fail-closed paths -- this is the guard above one level deeper. A missing `answers` is left+ # alone: that is the no-decision case the consumers already handle, not a malformed one.+ if "answers" in parsed and not isinstance(parsed["answers"], dict):+ raise RuntimeError(+ f"Malformed decision response from Laya server at {url}: "+ f"'answers' must be a JSON object, got {type(parsed['answers']).__name__}"+ )return parseddiff --git a/laya/integrations/crewai.py b/laya/integrations/crewai.pyindex b5d703e4..06abadcc 100644--- a/laya/integrations/crewai.py+++ b/laya/integrations/crewai.py@@ -213,6 +213,16 @@ def _call_remote(f"Malformed decision response from Laya server at {url}: "f"expected a JSON object, got {type(parsed).__name__}")+ # `parsed` is an object now, but its `answers` field is the same arbitrary JSON: a gateway can+ # answer `{"answers": []}`. Both consumers read it as `res.get("answers", {})` and then call+ # `.get("delegation", …)` / `.items()` on it, so a non-object there leaks AttributeError past the+ # same fail-closed paths -- this is the guard above one level deeper. A missing `answers` is left+ # alone: that is the no-decision case the consumers already handle, not a malformed one.+ if "answers" in parsed and not isinstance(parsed["answers"], dict):+ raise RuntimeError(+ f"Malformed decision response from Laya server at {url}: "+ f"'answers' must be a JSON object, got {type(parsed['answers']).__name__}"+ )return parseddiff --git a/laya/integrations/langchain.py b/laya/integrations/langchain.pyindex 4ef37f31..48541bfa 100644--- a/laya/integrations/langchain.py+++ b/laya/integrations/langchain.py@@ -223,6 +223,17 @@ def _call_remote(f"Malformed decision response from Laya server at {url}: "f"expected a JSON object, got {type(parsed).__name__}")+ # `parsed` is an object now, but its `answers` field is the same arbitrary JSON: a gateway can+ # answer `{"answers": []}`. The consumers read it four ways -- `result["answers"][question_id]`,+ # `.get("answers", {}).get("intent", …)`, `.items()` and one that hands it back to the caller --+ # so a non-object leaks TypeError/AttributeError, or worse a non-mapping into user code, past the+ # fail-closed paths. This is the guard above one level deeper. A missing `answers` is left alone:+ # `LayaRouter` already reports that as its own KeyError, and the guardrail as no violations.+ if "answers" in parsed and not isinstance(parsed["answers"], dict):+ raise RuntimeError(+ f"Malformed decision response from Laya server at {url}: "+ f"'answers' must be a JSON object, got {type(parsed['answers']).__name__}"+ )return parseddiff --git a/laya/integrations/llamaindex.py b/laya/integrations/llamaindex.pyindex 90a71527..ab1ca0c7 100644--- a/laya/integrations/llamaindex.py+++ b/laya/integrations/llamaindex.py@@ -209,6 +209,16 @@ def _call_remote(f"Malformed decision response from Laya server at {url}: "f"expected a JSON object, got {type(parsed).__name__}")+ # `parsed` is an object now, but its `answers` field is the same arbitrary JSON: a gateway can+ # answer `{"answers": []}`. The selector, the multi-selector and the query router each read it as+ # `res.get("answers", {})` and then call `.get("selector"/"route", …)` on it, so a non-object there+ # leaks AttributeError past the same fail-closed paths -- this is the guard above one level deeper.+ # A missing `answers` is left alone: that is the no-decision case they already handle.+ if "answers" in parsed and not isinstance(parsed["answers"], dict):+ raise RuntimeError(+ f"Malformed decision response from Laya server at {url}: "+ f"'answers' must be a JSON object, got {type(parsed['answers']).__name__}"+ )return parsed