Bird
0
0

You want to create a few-shot prompt template that filters out examples with empty outputs before formatting. Which approach correctly applies this filtering in Langchain?

hard📝 Application Q15 of 15
LangChain - Prompt Templates
You want to create a few-shot prompt template that filters out examples with empty outputs before formatting. Which approach correctly applies this filtering in Langchain?
AFilter the examples list before passing it to FewShotPromptTemplate constructor
BUse a custom example_prompt that skips empty outputs during formatting
CSet prefix to None and rely on Langchain to ignore empty outputs
DPass all examples and filter outputs after calling prompt_template.format()
Step-by-Step Solution
Solution:
  1. Step 1: Understand filtering in few-shot templates

    FewShotPromptTemplate uses the examples list as-is; filtering must happen before passing examples.
  2. Step 2: Evaluate options for filtering

    Only filtering the examples list before creating the template ensures empty outputs are excluded properly.
  3. Final Answer:

    Filter the examples list before passing it to FewShotPromptTemplate constructor -> Option A
  4. Quick Check:

    Pre-filter examples before constructor = A [OK]
Quick Trick: Filter examples before creating the prompt template [OK]
Common Mistakes:
  • Trying to filter inside example_prompt formatting
  • Assuming Langchain auto-filters empty outputs
  • Filtering after formatting instead of before

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes