Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Sep 8, 2025

Important

Set cost_details to zero on errors in CallbackHandler.py to prevent incorrect cost reporting.

  • Error Handling:
    • Set cost_details to {"total": 0} in on_retriever_error(), on_chain_error(), on_tool_error(), and on_llm_error() in CallbackHandler.py to ensure cost is zero on errors.

This description was created by Ellipsis 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.py file to set cost details to zero when exceptions or errors are encountered during LLM operations.

PR Description Notes:

  • The PR description is missing, making it difficult to understand the specific issue being addressed or the rationale behind the change
  • No linked GitHub issue or discussion is referenced, which goes against the contributing guidelines

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

  • This PR is not ready to merge due to missing context and potential compliance issues
  • Score reflects lack of PR description, missing issue reference, and insufficient information to assess the technical implementation
  • Pay close attention to the CallbackHandler.py file and require proper documentation before proceeding

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)

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

level="ERROR",
status_message=str(error),
input=kwargs.get("inputs"),
cost_details={"total": 0},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good: cost_details set to {"total": 0} on retriever errors. Consider extracting the literal to a constant if used in multiple error handlers.

@hassiebp hassiebp disabled auto-merge September 8, 2025 12:28
@hassiebp hassiebp merged commit fed7240 into main Sep 8, 2025
6 of 10 checks passed
@hassiebp hassiebp deleted the hassieb/lfe-6403-langchain-error-cost branch September 8, 2025 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Cost is tracked for failed calls (prompt too long) for Anthropic. Gemini is working fine (cost not tracked for failed traces)

2 participants