Bird
0
0

You wrote this callback handler but streaming output is not showing:

medium📝 Debug Q6 of 15
LangChain - Production Deployment
You wrote this callback handler but streaming output is not showing:
class MyHandler(BaseCallbackHandler):
    def on_llm_new_token(self, token):
        print(token)

What is the likely issue?
ACallback class must inherit from StreamingCallbackHandler.
BMissing **kwargs parameter in on_llm_new_token method.
Cprint() cannot be used inside callbacks.
Dstreaming=True must be set inside the callback class.
Step-by-Step Solution
Solution:
  1. Step 1: Check method signature requirements

    on_llm_new_token requires token and **kwargs parameters.
  2. Step 2: Identify missing **kwargs

    Missing **kwargs causes method not to match expected signature, so callback is ignored.
  3. Final Answer:

    Missing **kwargs parameter in on_llm_new_token method. -> Option B
  4. Quick Check:

    Callback methods need correct parameters [OK]
Quick Trick: Include **kwargs in callback methods to avoid signature errors [OK]
Common Mistakes:
MISTAKES
  • Thinking inheritance must be StreamingCallbackHandler
  • Assuming print() is disallowed
  • Believing streaming flag belongs in callback class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes