Bird
0
0

You want to deploy a LangServe API that returns the length of the input string only if it is longer than 5 characters. Which class correctly implements this?

hard📝 component behavior Q8 of 15
LangChain - Production Deployment
You want to deploy a LangServe API that returns the length of the input string only if it is longer than 5 characters. Which class correctly implements this?
Aclass LengthAPI: def __call__(self, input): if len(input) > 5: return len(input) return 'Too short'
Bclass LengthAPI: def __call__(self, input): return len(input) if input > 5 else 'Too short'
Cclass LengthAPI: def __call__(self, input): if input > 5: return len(input) return 'Too short'
Dclass LengthAPI: def __call__(self, input): return len(input) > 5
Step-by-Step Solution
Solution:
  1. Step 1: Check condition on string length

    We must check if len(input) > 5, not input > 5.
  2. Step 2: Verify return values

    class LengthAPI: def __call__(self, input): if len(input) > 5: return len(input) return 'Too short' returns length if condition true, else 'Too short'. Others misuse condition or return wrong types.
  3. Final Answer:

    class LengthAPI:\n def __call__(self, input):\n if len(input) > 5:\n return len(input)\n return 'Too short' -> Option A
  4. Quick Check:

    Check string length with len(input) > 5 [OK]
Quick Trick: Use len(input) to check string length, not input > number [OK]
Common Mistakes:
MISTAKES
  • Comparing string directly to number
  • Returning boolean instead of length
  • Missing else return value

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes