Repository navigation
Conversation
The LangChain branch sent a single prompt to agenerate_prompt() but the parse loop read resp.generations[0][i] for i in range(n), so n > 1 raised IndexError instead of returning n outputs. Batch n prompt copies and read each generation from its own batch result, mirroring PydanticPrompt.generate_multiple. Also warn and proceed when the LLM returns fewer generations than requested instead of crashing.
1985312383
pushed a commit
to datawhalechina/tally-judge
that referenced
this pull request
Nov 14, 2026
The LangChain branch sent a single prompt to agenerate_prompt() but the parse loop read resp.generations[0][i] for i in range(n), so n > 1 raised IndexError instead of returning n outputs. Batch n prompt copies and read each generation from its own batch result, mirroring PydanticPrompt.generate_multiple. Also warn and proceed when the LLM returns fewer generations than requested instead of crashing. Upstream-PR: vibrantlabsai/ragas#3058 (cherry picked from commit bc6451f)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue Link / Problem Description
multi_modal/ImageTextPrompt/IndexError), so describing the problem here.ImageTextPrompt.generate_multiple(part of the publicBasePromptAPI,src/ragas/prompt/base.py:53) raisesIndexErrorwhen called withn > 1and a LangChain LLM.Root cause: with a LangChain LLM the method sends a single prompt —
agenerate_prompt([prompt_value])(src/ragas/prompt/multi_modal_prompt.py:176-180onmain) — so the response holds exactly one generation. The parse loop then runsfor i in range(n): resp.generations[0][i].text(multi_modal_prompt.py:194-195onmain), which raisesIndexError: list index out of rangeas soon asn > 1.Reproducer:
The sibling
PydanticPrompt.generate_multiplealready handles this case: it batchesnprompt copies for LangChain LLMs (src/ragas/prompt/pydantic_prompt.py:243-252) and clamps the parse loop withavailable_generations/actual_n, warning instead of crashing (pydantic_prompt.py:288-306).ImageTextPromptwas missing the same handling.Changes Made
src/ragas/prompt/multi_modal_prompt.py: ingenerate_multiple, the LangChain branch now sendsncopies of the prompt toagenerate_prompt()and each output is read from its own batch result (resp.generations[i][0].text), mirroringPydanticPrompt.generate_multiple. The parse loop is clamped to the number of generations actually returned (actual_n = min(n, available_generations)): aValueErroris raised if the LLM returned none, and a warning is logged when it returned fewer than requested — identical to the sibling implementation.tests/unit/prompt/test_multi_modal_prompt.py(new): regression tests forn=1andn=2with a LangChain LLM,n > 1with a Ragas LLM, and graceful degradation when a Ragas LLM returns fewer generations than requested.Testing
How to Test
IndexErroronmainand returns two outputs with this patch (verified with the same fake-LLM setup as the regression tests, run against both the unpatched and the patched tree).References
PydanticPrompt.generate_multiple(src/ragas/prompt/pydantic_prompt.py:243-252,288-314)BasePrompt.generate_multiple(src/ragas/prompt/base.py:53)Screenshots/Examples (if applicable)
Reproducer behavior with the patch:
IndexError: list index out of range[Out(answer='42'), Out(answer='43')]