Repository navigation
fix(structured): a non-dict answer is omitted from the projection, not fatal - #1368
Conversation
…t fatal decide() and answers_to_json() read .get off every answer, so a field whose answer was not an object -- a bare string/number/list -- raised AttributeError and crashed the whole result. apply_confidence_gate already skips a non-dict answer (confidence.py:298); _project and _details now make the same call and omit the field, exactly as an absent (None) answer already does.
8 PRs. Rust and .NET batch prediction and router batch APIs (#1358, #1359), the min_confidence abstention gate and jev_confidence in both ports (#1362, #1363), and four inputs refused where they enter instead of failing later (#1365, #1366, #1367, #1368). Verified before tagging: all 92 suites pass, 612 tests. ruff clean on both lists. Java fixture, Unicode table and language table gates clean; three Go tables_gen.go match. Version agrees across pyproject.toml, laya.__version__ and nix/package.nix. README carries 0.4.16 only. Security audit of the merge diff, 180330 added lines over 349 files: zero dynamic exec, zero network calls, zero URLs, zero base64 or obfuscation, zero secrets in the diff or the tracked tree, zero laya-max boundary hits, no writes outside the test temp dir, the dependency surface untouched, no npm install hooks, no binaries, every new file 100644, and 20 of 20 actions SHA-pinned with codeql-action init, autobuild and analyze all on 4.39.1. Held from this release: #1364 (correct in Python but it moves a cross-port contract Decisions.java reproduces deliberately and structured.ts shares), #1324 (real table regression), and seven dependency and action bumps for a pass of their own. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Merged, in 0.4.16. The argument that settles this is that Fixing Citing |
…the oracle omits it laya/structured.py skips an answer that is not an object (isinstance(answer, dict), #1368); the port only skipped null/undefined, so a string, number, boolean or array under a field name was read field-by-field and invented a value -- "undefined" for a choice, minimum+0 for a score, false for a noul, plus confidence 0.0 / answerConfidence null / probabilities {} in the details. Measured across 4 fields x 6 shapes: 40 of 48 rows disagreed with Python, 0 after. Arrays need their own check because typeof reports them as "object".
What
laya/structured.py::_projectand::_detailscallanswer.get(...)on every value inanswers. When a field's answer is not an object -- a runner (or a cached/replayed decision) that reports"department": "oops"or a list instead of{"type": ..., "choice": ...}-- that raised a rawAttributeError: 'str' object has no attribute 'get'and crashed the entire projection, taking down the schema fields that were well-formed.The same happens through the public entry points:
decide(runner, state, schema=...),decide(..., return_details=True), andanswer_to_pydantic.Why
apply_confidence_gatewalks those exact same answer objects on the samedecidecode path (structured.py:370, two lines before_projectruns) and deliberately skips a non-dict answer --if not isinstance(a, dict): continue(confidence.py:298). So the module already treats a non-dict answer as "no answer". Only the projection disagreed: it crashed where its sibling skips._projectalready omits a field whose answer is absent (answer is None: continue); this extends that same omission to a non-dict answer, so projection and gate agree and one corrupt field no longer sinks the whole result. Well-formed answers project byte-for-byte unchanged (isinstance(answer, dict)is true for all of them).How it was verified
Cases go into the already-registered
tests/test_structured.py: three in the projection section (non-dict answers omitted, valid fields still project, all-non-dict yields{}) and three after thedecide/details block (scalar answer throughdecideand throughreturn_details).Checklist
test_hooks_api.pystill green — only the malformed-input behaviour moves from crash to omission, matching the gate)