#681·laya

fix(structured): score projection ignores minimum when probabilities are absent

Author: rahul05ranjanCreated Sep 28, 2026Updated Oct 1, 2026

Summary

\laya.structured._project\ maps a \score\ answer to its schema value. When the answer carries \probabilities, it uses the argmax index and returns \minimum + idx. When \probabilities\ is absent, it computes \idx = round(score) - minimum\ and then returns \minimum + idx\ — which cancels out to
ound(score), ignoring \minimum\ entirely.

Repro

\\python from laya.structured import answers_to_json schema = {'type': 'object', 'properties': {'level': {'type': 'integer', 'minimum': 1, 'maximum': 3}}}

model confident in level 3 (0-based index 2), no probabilities

ans = {'level': {'type': 'score', 'score': 2.0, 'confidence': 0.9}} print(answers_to_json(ans, schema)['level']) # 2, expected 3 \\

Impact

For any score field whose \minimum\ is not 0, a decision projected without \probabilities\ returns a value shifted down by \minimum. The docs state the contract is \minimum + argmax\ (docs/structured.md), and the agent's \score\ field is the 0-based level index (its \legend\ keys levels 0..k-1), so the projected value must be \minimum + round(score).

Fix

Drop the - minimum\ from the no-probabilities branch: \idx = int(round(float(answer.get('score', 0.0)))).