0
0
LangChainframework~10 mins

Why structured output matters in LangChain - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define a structured output parser in LangChain.

LangChain
from langchain.output_parsers import [1]

parser = [1]()
Drag options to blanks, or click blank then click option'
AStructuredOutputParser
BSimpleOutputParser
CTextOutputParser
DJsonOutputParser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parser that only handles plain text instead of structured data.
2fill in blank
medium

Complete the code to specify the output schema for structured output.

LangChain
from langchain.output_parsers import [1]

schema = [1](name="answer", description="The final answer")
parser = StructuredOutputParser.from_schemas([schema])
Drag options to blanks, or click blank then click option'
AOutputSchema
BInputSchema
CDataSchema
DResponseSchema
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing input schema with output schema.
3fill in blank
hard

Fix the error in the code to correctly parse the structured output.

LangChain
response = '{"answer": "42"}'
parsed = parser.[1](response)
Drag options to blanks, or click blank then click option'
Aparse
Bparse_text
Cparse_json
Dparse_response
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods that do not exist or are not part of the parser API.
4fill in blank
hard

Fill both blanks to create a prompt template that uses structured output parsing.

LangChain
from langchain.prompts import PromptTemplate

prompt = PromptTemplate(
    template="Answer the question: {question}",
    input_variables=[[1]],
    output_parser=[2]
)
Drag options to blanks, or click blank then click option'
A"question"
B"answer"
Cparser
Dschema
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names or forgetting to match input variables with template placeholders.
5fill in blank
hard

Fill all three blanks to extract the structured output and access the answer value.

LangChain
result = parser.parse([1])
answer = result.[2]
print(f"The answer is: [3]")
Drag options to blanks, or click blank then click option'
Aresponse
Banswer
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing variable names or trying to print the wrong variable.