Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the JsonOutputParser from langchain.
LangChain
from langchain.output_parsers import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'JsonParser' instead of 'JsonOutputParser'.
Importing from the wrong module.
✗ Incorrect
The correct import is JsonOutputParser from langchain.output_parsers.
2fill in blank
mediumComplete the code to create a JsonOutputParser instance with a given schema.
LangChain
parser = JsonOutputParser([1]=schema) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'output_schema' or 'json_schema' instead of 'schema'.
Passing the schema as a positional argument.
✗ Incorrect
The parameter name for the schema is schema.
3fill in blank
hardFix the error in the code to parse a JSON string using the parser.
LangChain
result = parser.[1](json_string) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'load' which is for file reading.
Using 'parse_json' which does not exist.
✗ Incorrect
The method to parse JSON output is parse.
4fill in blank
hardFill both blanks to define a JSON schema and create the parser.
LangChain
schema = [1](type="object", properties={"name": {"type": "string"}}) parser = JsonOutputParser([2]=schema)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class name for schema.
Passing schema with wrong parameter name.
✗ Incorrect
The schema is defined using JSONSchemaType and passed as schema to the parser.
5fill in blank
hardFill both blanks to parse JSON output and extract the 'name' field.
LangChain
parsed = parser.[1](json_output) name = parsed"name" print([2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation instead of brackets for dictionary access.
Printing the wrong variable.
✗ Incorrect
Use parse to parse, then access the 'name' key with brackets, and print the variable name.