-
Notifications
You must be signed in to change notification settings - Fork 344
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: arpan sahu <28574248+arpansahu@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude Code Review
This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.
CLAassistant
commented
Aug 27, 2026
CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
arpansahu
commented
Aug 27, 2026
Disclosure: this contribution was prepared with AI assistance (GitHub Copilot CLI), and
I am flagging that explicitly rather than leaving you to guess.
The defect, the fix and the regression test were verified locally: the new test fails on
unmodified upstream and passes with the change applied, and the surrounding suite is green.
If your project would prefer not to take AI-assisted contributions, or you would rather this
were reworked and resubmitted by hand, please just close it -- no objection at all, and
apologies for the noise.
Uh oh!
There was an error while loading. Please reload this page.
Problem
CallbackHandler.on_llm_end()assumes every LangChainLLMResultcontains at least one generation in the last generation batch. If a provider returns an empty generation batch but still includes model and usage metadata, the callback raisesIndexError, logs the error, and never ends the generation span.Reproducer
Fix
Extract the last available generation by skipping empty generation batches, and use
Noneas the output when no generation is present. This keeps the span lifecycle correct while preserving existing output extraction for normal chat and text generations.Testing
python -m pytest tests\\unit\\test_langchain.py::test_llm_callback_ends_generation_with_empty_generations -qfailed before the fix and passed after.python -m pytest tests\\unit\\test_langchain.py -q-> 24 passed.ruff format langfuse\\langchain\\CallbackHandler.py tests\\unit\\test_langchain.py --check-> passed after formatting.ruff check langfuse\\langchain\\CallbackHandler.py tests\\unit\\test_langchain.py-> All checks passed.Note: full offline
tests\\unitbaseline still has pre-existing Windows/environment failures unrelated to this change (test_path, prompt subprocess missingopentelemetry, and prompt mock errors).Greptile Summary
The PR makes LangChain LLM completion handling tolerate empty generation batches so generation spans can still finish with model and usage metadata.
Nonewhen none exists.Confidence Score: 5/5
The PR appears safe to merge with no actionable correctness, security, or quality issues identified.
The empty-result path now avoids indexing an empty batch, safely passes
Nonethrough the observation update, preserves model and usage metadata, and ends the generation span.Reviews (1): Last reviewed commit: "fix(langchain): handle empty llm generat..." | Re-trigger Greptile