Bird
0
0

Identify the error in this Langchain prompt formatting code:

medium📝 Debug Q6 of 15
LangChain - RAG Chain Construction
Identify the error in this Langchain prompt formatting code:
template = "User: {user}
Task: {task}"
prompt = template.format(user="Eve")
print(prompt)
AMissing variable 'task' causes KeyError at runtime
BSyntax error due to missing comma in format()
CIncorrect placeholder syntax with curly braces
DNo error, code runs and prints correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check placeholders and format arguments

    Template has two placeholders: {user} and {task}. Only 'user' is provided in format.
  2. Step 2: Understand Python format behavior

    Missing 'task' argument causes KeyError when format() runs.
  3. Final Answer:

    Missing variable 'task' causes KeyError at runtime -> Option A
  4. Quick Check:

    Missing format variable = KeyError [OK]
Quick Trick: All placeholders must be matched in format() call [OK]
Common Mistakes:
  • Thinking missing variables cause syntax errors
  • Assuming code runs without error
  • Confusing placeholder syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes