Bird
0
0

You wrote this code to create evaluation examples but get an error:

medium📝 Debug Q14 of 15
LangChain - Evaluation and Testing
You wrote this code to create evaluation examples but get an error:
examples = [{"query": "Who wrote Hamlet?", "answer": "Shakespeare"}]
chain = QAEvalChain.from_llm(llm=some_llm)
results = chain.evaluate(examples)
print(results)
What is the likely cause of the error?
AThe variable some_llm is not defined
BThe key 'answer' should be 'expected_answer' in the example dictionary
CQAEvalChain does not have an evaluate method
DThe examples list should be empty
Step-by-Step Solution
Solution:
  1. Step 1: Check example dictionary keys

    LangChain expects 'expected_answer' key, not 'answer', for evaluation examples.
  2. Step 2: Identify mismatch causing error

    Using 'answer' instead of 'expected_answer' causes the chain to fail reading expected answers.
  3. Final Answer:

    The key 'answer' should be 'expected_answer' in the example dictionary -> Option B
  4. Quick Check:

    Correct key name = 'expected_answer' [OK]
Quick Trick: Use 'expected_answer' key, not 'answer' in examples [OK]
Common Mistakes:
MISTAKES
  • Using wrong key names in example dictionaries
  • Assuming method names without checking docs
  • Ignoring variable definitions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes