Challenge - 5 Problems
Few-shot Prompt Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this few-shot prompt template code?
Consider this LangChain few-shot prompt template code snippet. What will be the final prompt text after rendering?
LangChain
from langchain.prompts import FewShotPromptTemplate, PromptTemplate examples = [ {"input": "Hello", "output": "Hi there!"}, {"input": "Bye", "output": "Goodbye!"} ] example_prompt = PromptTemplate( input_variables=["input", "output"], template="Input: {input}\nResponse: {output}" ) few_shot = FewShotPromptTemplate( examples=examples, example_prompt=example_prompt, prefix="You are a helpful assistant.", suffix="Input: {user_input}\nResponse:", input_variables=["user_input"] ) final_prompt = few_shot.format(user_input="Hello") print(final_prompt)
Attempts:
2 left
💡 Hint
Look at how the examples are formatted and how the suffix uses the user input.
✗ Incorrect
The FewShotPromptTemplate inserts all examples formatted by example_prompt between prefix and suffix. The suffix includes the new user input, waiting for the model's response.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a FewShotPromptTemplate with multiple input variables?
You want to create a FewShotPromptTemplate that uses examples with inputs 'question' and 'answer', and a suffix that takes 'new_question'. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Check that the suffix uses the same variable name as in input_variables.
✗ Incorrect
The suffix uses {new_question}, so input_variables must include 'new_question'. The example_prompt uses 'question' and 'answer' for examples.
🔧 Debug
advanced2:00remaining
What error does this FewShotPromptTemplate code raise?
This code tries to create a FewShotPromptTemplate but fails. What error will it raise?
LangChain
from langchain.prompts import FewShotPromptTemplate, PromptTemplate examples = [{"input": "Hi", "output": "Hello!"}] example_prompt = PromptTemplate( input_variables=["input", "output"], template="Input: {input}\nOutput: {output}" ) few_shot = FewShotPromptTemplate( examples=examples, example_prompt=example_prompt, prefix="Start conversation.", suffix="Input: {user_input}\nOutput:", input_variables=["user_input", "extra"] ) few_shot.format(user_input="Hi")
Attempts:
2 left
💡 Hint
Check which variables are used in suffix and prefix versus input_variables.
✗ Incorrect
The input_variables list includes 'extra' which is not used in prefix or suffix, so when formatting without 'extra', a KeyError occurs.
❓ state_output
advanced2:00remaining
What is the number of example blocks in the rendered prompt?
Given this FewShotPromptTemplate with 3 examples, how many example blocks appear in the final prompt string?
LangChain
examples = [
{"q": "What is AI?", "a": "Artificial Intelligence."},
{"q": "What is ML?", "a": "Machine Learning."},
{"q": "What is NLP?", "a": "Natural Language Processing."}
]
example_prompt = PromptTemplate(
input_variables=["q", "a"],
template="Q: {q}\nA: {a}"
)
few_shot = FewShotPromptTemplate(
examples=examples,
example_prompt=example_prompt,
prefix="Answer the following questions.",
suffix="Q: {new_q}\nA:",
input_variables=["new_q"]
)
prompt_text = few_shot.format(new_q="What is Python?")Attempts:
2 left
💡 Hint
Count how many example dictionaries are in the examples list.
✗ Incorrect
The examples list has 3 items, so 3 example blocks appear in the prompt.
🧠 Conceptual
expert2:00remaining
Which statement best describes the role of 'example_prompt' in FewShotPromptTemplate?
In LangChain's FewShotPromptTemplate, what is the main purpose of the 'example_prompt' parameter?
Attempts:
2 left
💡 Hint
Think about how examples become text in the prompt.
✗ Incorrect
The example_prompt is a PromptTemplate that formats each example dictionary into a text block to be included in the prompt.