0
0
LangChainframework~10 mins

Auto-fixing malformed output in LangChain - Interactive Code Practice

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

Complete the code to import the necessary class for output fixing in LangChain.

LangChain
from langchain.output_parsers import [1]
Drag options to blanks, or click blank then click option'
AAutoFixOutputParser
BOutputFixerParser
CMalformedOutputFixer
DOutputCleaner
Attempts:
3 left
💡 Hint
Common Mistakes
Using a class name that does not exist in LangChain.
Confusing output cleaning with output fixing.
2fill in blank
medium

Complete the code to create an instance of the auto-fixing output parser.

LangChain
parser = [1]()
Drag options to blanks, or click blank then click option'
AAutoFixOutputParser
BOutputFixerParser
CMalformedOutputFixer
DOutputCleaner
Attempts:
3 left
💡 Hint
Common Mistakes
Instantiating a non-existent class.
Using a class meant for cleaning instead of fixing.
3fill in blank
hard

Fix the error in the code to parse a malformed output string correctly.

LangChain
fixed_output = parser.parse([1])
Drag options to blanks, or click blank then click option'
A'{"answer": 42}'
B'{answer: 42}'
C'{"answer": "42"}'
D'answer: 42'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing already valid JSON strings which do not demonstrate fixing.
Passing strings without braces.
4fill in blank
hard

Fill both blanks to create a parser that fixes output and then parse a malformed string.

LangChain
parser = [1]()
result = parser.[2]('{answer: "yes"}')
Drag options to blanks, or click blank then click option'
AAutoFixOutputParser
Bparse
Cparse_output
DOutputFixerParser
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong method name like 'parse_output'.
Using a wrong class name.
5fill in blank
hard

Fill all three blanks to define a function that uses the auto-fixing parser to fix and return parsed output.

LangChain
def fix_and_parse(output_str):
    parser = [1]()
    fixed = parser.[2](output_str)
    return fixed.[3]
Drag options to blanks, or click blank then click option'
AAutoFixOutputParser
Bparse
Cparsed
Dresult
Attempts:
3 left
💡 Hint
Common Mistakes
Returning the parser instance instead of the parsed result.
Using incorrect attribute names like 'parsed'.