fix: derive ranker ranking from structured scores instead of LLM array

The JSON parsing path returned the LLM's explicit ranking array,
which sometimes contradicted its own per-dimension scores. Use
_scores_to_ranking() to compute the ranking from weighted scores
when available, falling back to the LLM ranking only when scores
are absent.
This commit is contained in:
Kevin Turcios 2026-02-23 03:37:42 -05:00
parent 20ee6d5b62
commit 85a1c8b183

View file

@ -384,8 +384,13 @@ async def rank_optimizations( # noqa: D417
json_response = _parse_json_response(output.content, num_candidates)
if json_response is not None:
logging.info("Successfully parsed JSON response")
ranking = (
_scores_to_ranking(json_response.scores)
if json_response.scores is not None
else json_response.ranking
)
return RankResponseSchema(
ranking=json_response.ranking, explanation=json_response.explanation, scores=json_response.scores
ranking=ranking, explanation=json_response.explanation, scores=json_response.scores
)
# Fall back to regex parsing (legacy XML-tag format)