Bird
0
0

Which of the following is the correct way to add a callback for observability in a LangChain LLM chain?

easy📝 Syntax Q12 of 15
LangChain - LangSmith Observability
Which of the following is the correct way to add a callback for observability in a LangChain LLM chain?
Achain = LLMChain(llm=llm, prompt=prompt, handlers=MyCallbackHandler())
Bchain = LLMChain(llm=llm, prompt=prompt, callbacks=[MyCallbackHandler()])
Cchain = LLMChain(llm=llm, prompt=prompt, callback=MyCallbackHandler())
Dchain = LLMChain(llm=llm, prompt=prompt, observers=[MyCallbackHandler()])
Step-by-Step Solution
Solution:
  1. Step 1: Recall LangChain callback syntax

    LangChain expects a list of callback handlers passed as the 'callbacks' parameter.
  2. Step 2: Match correct parameter and value type

    chain = LLMChain(llm=llm, prompt=prompt, callbacks=[MyCallbackHandler()]) uses 'callbacks' with a list containing the handler instance, which is correct.
  3. Final Answer:

    chain = LLMChain(llm=llm, prompt=prompt, callbacks=[MyCallbackHandler()]) -> Option B
  4. Quick Check:

    Callbacks param = list of handlers [OK]
Quick Trick: Callbacks parameter takes a list of handler instances [OK]
Common Mistakes:
MISTAKES
  • Using 'callback' instead of 'callbacks'
  • Passing a single handler without list brackets
  • Using wrong parameter names like 'handlers' or 'observers'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes