fix(langchain): set cost to zero on errors #1328
Merged
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.
Important
Set
cost_detailsto zero on errors inCallbackHandler.pyto prevent incorrect cost reporting.cost_detailsto{"total": 0}inon_retriever_error(),on_chain_error(),on_tool_error(), andon_llm_error()inCallbackHandler.pyto ensure cost is zero on errors.This description was created by
for 069443f. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Summary
Updated On: 2025-09-08 11:41:11 UTC
This PR addresses cost calculation handling in the Langchain integration's CallbackHandler when errors occur. The change appears to modify the
CallbackHandler.pyfile to set cost details to zero when exceptions or errors are encountered during LLM operations.PR Description Notes:
The modification likely prevents incorrect cost calculations from being recorded when LLM calls fail, ensuring that failed operations don't contribute misleading cost metrics to traces. This change fits into Langfuse's broader cost tracking functionality by providing more accurate cost attribution when errors occur in Langchain-integrated workflows.
Confidence score: 0/5
Context used:
Rule - Open a GitHub issue or discussion first before submitting PRs to explain the rationale and necessity of the proposed changes, as required by the contributing guide. (link)