Bird
0
0

What is the flaw in this Langchain retry snippet?

medium📝 Debug Q6 of 15
LangChain - LLM and Chat Model Integration
What is the flaw in this Langchain retry snippet?
try:
    result = client.call()
except RateLimitError:
    time.sleep(3)
    client.call()
ASleeping before retry is unnecessary and slows down the program
BThe second call is not inside a try-except, so errors may go unhandled
CThe code retries infinitely without a limit
DRateLimitError cannot be caught in Langchain
Step-by-Step Solution
Solution:
  1. Step 1: Review retry logic

    After catching RateLimitError, the code retries once after sleeping.
  2. Step 2: Identify missing error handling

    The retry call is not wrapped in try-except, so if it fails again, exception propagates.
  3. Final Answer:

    The second call is not inside a try-except, so errors may go unhandled -> Option B
  4. Quick Check:

    Retry calls need their own exception handling [OK]
Quick Trick: Retry calls must be wrapped in try-except [OK]
Common Mistakes:
  • Assuming sleep is unnecessary
  • Believing retries are infinite here
  • Thinking RateLimitError cannot be caught

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes