Fix Langfuse callback passthrough in RunnableRails (#472)#1390
Fix Langfuse callback passthrough in RunnableRails (#472)#1390divya-garak wants to merge 1 commit intoNVIDIA-NeMo:developfrom
Conversation
Fixes NVIDIA-NeMo#472: The langchain runnable was not called with the runnable config that defines callbacks, breaking Langfuse tracing integration. Changes: - Store RunnableConfig and kwargs from invoke() for use in passthrough function - Pass stored config to underlying runnable to preserve callbacks - Add test to verify callback passthrough functionality This ensures that callbacks (like Langfuse tracing) are properly propagated to the underlying LLM runnable wrapped in RunnableRails.
There was a problem hiding this comment.
Pull Request Overview
This PR fixes Langfuse callback passthrough in RunnableRails when integrated with LangChain chains by ensuring the RunnableConfig containing callbacks is properly propagated to the underlying runnable.
- Modified RunnableRails to store config and kwargs from invoke() method for later use in passthrough function
- Updated passthrough function to use stored config when invoking the underlying runnable
- Added comprehensive test to verify callback propagation functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| nemoguardrails/integrations/langchain/runnable_rails.py | Added instance variables to store current config/kwargs and modified passthrough function to use them |
| tests/test_runnable_rails.py | Added test case to verify RunnableConfig callbacks are properly passed through to underlying runnable |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| self.config = config | ||
| self.kwargs = kwargs |
There was a problem hiding this comment.
There's duplicate assignment here. Both self.config and self._current_config are assigned the same value, as are self.kwargs and self._current_kwargs. Consider removing the redundant assignments to self.config and self.kwargs since they appear to be legacy variables that are now replaced by the _current_* variants.
| self.config = config | |
| self.kwargs = kwargs |
Summary
Fixes #472: This PR resolves the issue where Langfuse tracing integration was broken when using NeMo-Guardrails with LangChain chains.
The problem was that the
RunnableConfigcontaining callbacks wasn't being properly passed through to the underlying LLM runnable in the passthrough function.Changes Made
RunnableRails.invoke()to store theRunnableConfigand kwargs for later use in the passthrough function_init_passthrough_fn()to use the stored config when invoking the passthrough runnabletest_runnable_config_callback_passthrough()to verify that callbacks are properly propagatedTechnical Details
The issue occurred because:
RunnableRails.invoke()received aconfigparameter with callbackspassthrough_fnwas called asynchronously through the Rails systemconfigwasn't available in the passthrough function scopeTesting
This ensures that tracing libraries like Langfuse work correctly when using RunnableRails in LangChain chains.