Bird
0
0

You want to monitor both the input prompts and the cost of API calls in your LangChain app. Which observability approach best achieves this?

hard📝 state output Q15 of 15
LangChain - LangSmith Observability
You want to monitor both the input prompts and the cost of API calls in your LangChain app. Which observability approach best achieves this?
AUse a callback handler that logs prompts on on_llm_start and tracks token usage on on_llm_end.
BAdd print statements inside the prompt template and ignore callbacks.
COnly log the final output text after the chain finishes.
DUse a callback that only tracks errors during chain execution.
Step-by-Step Solution
Solution:
  1. Step 1: Identify observability needs

    You want to see input prompts and monitor API call costs (token usage).
  2. Step 2: Match callback events to needs

    on_llm_start can log prompts; on_llm_end can provide token usage info for cost tracking.
  3. Step 3: Evaluate options

    Use a callback handler that logs prompts on on_llm_start and tracks token usage on on_llm_end. covers both prompt logging and cost monitoring via callbacks, which fits best.
  4. Final Answer:

    Use a callback handler that logs prompts on on_llm_start and tracks token usage on on_llm_end. -> Option A
  5. Quick Check:

    Callbacks on start/end = prompt + cost tracking [OK]
Quick Trick: Use callbacks on start and end to log prompts and costs [OK]
Common Mistakes:
MISTAKES
  • Ignoring callbacks and using print statements only
  • Logging only outputs misses input and cost info
  • Tracking only errors misses prompt and cost data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes