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(structured): refuse a boolean score bound instead of reading it as 1/0
Aashish1bac726f6190
diff --git a/laya/structured.py b/laya/structured.pyindex 4888abe5..407c5b33 100644--- a/laya/structured.py+++ b/laya/structured.py@@ -133,7 +133,14 @@ def _noul_field(path: str, name: str, description: Optional[str]) -> _Field:def _score_field(path: str, name: str, prop: Dict[str, Any],description: Optional[str]) -> _Field:lo, hi = prop.get("minimum"), prop.get("maximum")- if not isinstance(lo, int) or not isinstance(hi, int):+ # `bool` is a subclass of `int`, so `isinstance(True, int)` is true: a JSON `"minimum": true`+ # would otherwise slip through and silently become a bound of 1 (`"maximum": false` a bound of+ # 0), even though the same message rejects `"0"` and `1.5`. `_enum_field` below refuses a+ # `[true, false]` enum on the same principle -- a boolean is a yes/no, not a number -- so the+ # exclusion belongs here too, routed into the existing "needs integer" error the string and+ # float bounds already raise.+ if (isinstance(lo, bool) or isinstance(hi, bool)+ or not isinstance(lo, int) or not isinstance(hi, int)):raise SchemaError("%s: a numeric field needs integer 'minimum' and 'maximum' to become a score" % path)if hi < lo:diff --git a/tests/test_structured.py b/tests/test_structured.pyindex 440c59c9..a9fe94bb 100644--- a/tests/test_structured.py+++ b/tests/test_structured.py@@ -151,6 +151,22 @@ check_raises("reject/unbounded number", SchemaError,_bad({"type": "object", "properties": {"a": {"type": "integer", "minimum": 0}}}))check_raises("reject/score too wide", SchemaError,_bad({"type": "object", "properties": {"a": {"type": "integer", "minimum": 0, "maximum": 100}}}))+# A JSON boolean is not an integer scale bound. `bool` subclasses `int`, so `isinstance(True, int)` is+# true and a `minimum`/`maximum` of `true`/`false` used to slip through and silently become 1/0 -- even+# though the same guard rejects `"0"` (str) and `1.5` (float). Refuse them on the same message.+for bool_bound in ({"minimum": True, "maximum": 3}, {"minimum": 1, "maximum": False},+ {"minimum": False, "maximum": True}, {"minimum": True, "maximum": True}):+ check_raises("reject/boolean score bound %r" % bool_bound, SchemaError,+ _bad({"type": "object", "properties": {"a": {"type": "integer", **bool_bound}}}))+try:+ questions_from_json_schema({"type": "object", "properties": {"x": {"type": "integer", "minimum": True, "maximum": 3}}})+except SchemaError as exc:+ check("reject/boolean bound names the field and the integer rule", str(exc),+ "properties.x: a numeric field needs integer 'minimum' and 'maximum' to become a score")+# Positive control: a real integer bound still maps to a score scale (the guard is not over-strict).+check("accept/integer score bounds unchanged",+ questions_from_json_schema({"type": "object", "properties": {"x": {"type": "integer", "minimum": 1, "maximum": 3}}})+ ["x"]["criteria"], ["1", "2", "3"])check_raises("reject/too many properties", SchemaError,_bad({"type": "object", "properties": {("p%d" % i): {"type": "boolean"} for i in range(33)}}))check_raises("reject/too many options", SchemaError,