Challenge - 5 Problems
LangChain Output Fixer 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 LangChain output parser when given malformed JSON?
Consider a LangChain output parser designed to auto-fix malformed JSON outputs from a language model. Given the input string:
What will the parser output after auto-fixing?
{"name": "Alice", "age": 30,}What will the parser output after auto-fixing?
LangChain
from langchain.output_parsers import JsonOutputKeyToolsParser parser = JsonOutputKeyToolsParser() input_str = '{"name": "Alice", "age": 30,}' result = parser.parse(input_str) print(result)
Attempts:
2 left
💡 Hint
Think about how auto-fixing parsers handle trailing commas in JSON.
✗ Incorrect
The parser auto-fixes the trailing comma in the JSON string, resulting in a valid dictionary with keys 'name' and 'age'.
📝 Syntax
intermediate2:00remaining
Which option correctly fixes this malformed LangChain output with missing quotes?
Given this malformed output from a language model:
Which option shows the correctly auto-fixed output parser result?
{name: "Bob", age: 25}Which option shows the correctly auto-fixed output parser result?
LangChain
from langchain.output_parsers import JsonOutputKeyToolsParser parser = JsonOutputKeyToolsParser() input_str = '{name: "Bob", age: 25}' result = parser.parse(input_str) print(result)
Attempts:
2 left
💡 Hint
JSON keys must be strings with double quotes; auto-fix adds missing quotes.
✗ Incorrect
The parser adds missing double quotes around keys to produce valid JSON, then returns the dictionary.
🔧 Debug
advanced2:00remaining
What error does this LangChain output parser raise with unfixable malformed output?
Given this input string with unbalanced brackets:
What error will the LangChain output parser raise when trying to auto-fix?
{"city": "Paris", "country": "France"What error will the LangChain output parser raise when trying to auto-fix?
LangChain
from langchain.output_parsers import JsonOutputKeyToolsParser parser = JsonOutputKeyToolsParser() input_str = '{"city": "Paris", "country": "France"' result = parser.parse(input_str)
Attempts:
2 left
💡 Hint
Think about what happens when JSON is incomplete and cannot be fixed automatically.
✗ Incorrect
The parser tries to parse but fails due to missing closing bracket, raising JSONDecodeError.
❓ state_output
advanced2:00remaining
What is the value of the 'age' key after auto-fixing this LangChain output?
Given this malformed output string:
and a parser that expects 'age' as an integer and auto-fixes types, what will be the value of 'age' in the parsed output?
{"name": "Eve", "age": "twenty-five"}and a parser that expects 'age' as an integer and auto-fixes types, what will be the value of 'age' in the parsed output?
LangChain
from langchain.output_parsers import JsonOutputKeyToolsParser class CustomParser(JsonOutputKeyToolsParser): def parse(self, text): result = super().parse(text) if isinstance(result.get('age'), str): try: result['age'] = int(result['age']) except ValueError: result['age'] = None return result parser = CustomParser() input_str = '{"name": "Eve", "age": "twenty-five"}' result = parser.parse(input_str) print(result['age'])
Attempts:
2 left
💡 Hint
The string 'twenty-five' cannot convert to int, so the parser sets age to None.
✗ Incorrect
The parser tries to convert 'age' to int, fails, and assigns None to 'age'.
🧠 Conceptual
expert2:00remaining
Which option best describes the main limitation of auto-fixing malformed LangChain outputs?
Auto-fixing malformed outputs helps handle minor errors in language model responses. What is the main limitation of this approach?
Attempts:
2 left
💡 Hint
Think about what auto-fixing can and cannot do automatically.
✗ Incorrect
Auto-fixing mainly addresses syntax errors but cannot correct wrong meanings or complex data type mismatches.