Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
LangChain - Prompt Templates
Identify the error in this code snippet:

examples = [{"input": "Q1", "output": "A1"}]
example_prompt = PromptTemplate(input_variables=["input", "output"], template="Q: {input}\nA: {output}")
prompt = FewShotPromptTemplate(examples=examples, example_prompt=example_prompt, prefix="", suffix="Q: {input}\nA:")
AThe example_prompt should only have 'input' as input_variables
BThe examples list is empty
CThe suffix is missing required variables
DThe prefix cannot be an empty string
Step-by-Step Solution
Solution:
  1. Step 1: Check example_prompt input_variables

    FewShotPromptTemplate expects example_prompt to have only 'input' variable for formatting examples.
  2. Step 2: Identify mismatch with examples

    Examples have 'input' and 'output', but example_prompt input_variables includes both, which is incorrect.
  3. Final Answer:

    The example_prompt should only have 'input' as input_variables -> Option A
  4. Quick Check:

    example_prompt input_variables mismatch = C [OK]
Quick Trick: example_prompt input_variables must match FewShotPromptTemplate expectations [OK]
Common Mistakes:
  • Including 'output' in example_prompt input_variables
  • Assuming empty prefix is invalid
  • Ignoring suffix variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes