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(serve): a request with no state was answered about the literal text "null"
PerryLink60cac81eafbe
diff --git a/laya/serve.py b/laya/serve.pyindex afecb966..09d8ea5b 100644--- a/laya/serve.py+++ b/laya/serve.py@@ -105,9 +105,17 @@ def _resolve_port() -> int:def _check_request_limits(state: Any, questions: Any) -> None:- """Reject oversized inference requests before tokenization (413)."""+ """Reject absent or oversized inference requests before tokenization (400/413)."""from fastapi import HTTPException+ # `serialize_state(None)` is `json.dumps(None)` == the four characters `null`, so a body with+ # no `state` key, or `"state": null`, was answered as a decision about the literal text+ # "null" -- HTTP 200, and at ~0.94 confidence here, byte-identical to sending `"state":+ # "null"`. Nothing downstream can tell that apart from a real string, so the check has to+ # happen before serialization. The repo's other two surfaces already require a state:+ # examples/server.py declares it as a required field and mcp/tools.py rejects an empty one.+ if state is None:+ raise HTTPException(status_code=400, detail="'state' is required")if not isinstance(questions, dict):raise HTTPException(status_code=400, detail="'questions' must be an object")if len(questions) > MAX_QUESTIONS:diff --git a/tests/test_serve.py b/tests/test_serve.pyindex f2b80abb..e1380bd5 100644--- a/tests/test_serve.py+++ b/tests/test_serve.py@@ -402,3 +402,28 @@ def test_inference_timing_headers():assert "X-Inference-Time-Ms" in res.headersdur = float(res.headers["X-Inference-Time-Ms"])assert dur >= 0.0+++def test_a_missing_state_is_rejected_rather_than_answered():+ """No `state` key, or `"state": null`, must be a 400 and not a decision about "null".++ `serialize_state(None)` is `json.dumps(None)` -- the four characters `null` -- so the request+ was answered as a decision about that literal text: HTTP 200, byte-identical to sending+ `"state": "null"`, and at ~0.94 confidence on the real checkpoint. The caller gets an answer+ about a state they never supplied, with nothing in the response to say so.+ """+ router = FakeRouter()+ client = TestClient(create_app(router=router))+ questions = {"dept": {"type": "choice", "instructions": "which?",+ "criteria": {"billing": "invoices"}}}++ for body in ({"questions": questions}, # no state key+ {"state": None, "questions": questions}): # explicit null+ res = client.post("/v1/systemone", json=body)+ assert res.status_code == 400, (body, res.status_code, res.text)+ assert "'state' is required" in res.text, res.text++ # a state that IS a string is the caller's business, including the text "null" and ""+ for state in ("null", "", "0"):+ res = client.post("/v1/systemone", json={"state": state, "questions": questions})+ assert res.status_code == 200, (state, res.status_code, res.text)