Bird
0
0

Why does this code raise an error?

medium📝 Debug Q7 of 15
LangChain - Agents
Why does this code raise an error?
schema = {"input": "question", "output": "answer"}
agent = StructuredChatAgent(schema=schema, llm=llm)
response = agent.run({"query": "Hi"})
print(response)
ASchema is missing the 'llm' field
BInput dictionary key 'query' does not match schema's 'question'
CStructuredChatAgent cannot be initialized with a schema
Drun() method requires no arguments
Step-by-Step Solution
Solution:
  1. Step 1: Compare input keys with schema keys

    The schema expects an input field named 'question', but the input dictionary uses 'query'.
  2. Step 2: Understand schema validation

    Since the input key does not match the schema, the agent raises an error about missing required fields.
  3. Final Answer:

    Input dictionary key 'query' does not match schema's 'question' -> Option B
  4. Quick Check:

    Input keys must match schema keys exactly [OK]
Quick Trick: Input keys must match schema keys exactly [OK]
Common Mistakes:
MISTAKES
  • Assuming schema needs an 'llm' field
  • Thinking run() takes no arguments
  • Believing StructuredChatAgent can't use schemas

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes