0
0
LangChainframework~20 mins

Debugging failed chains in LangChain - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
LangChain Debugging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🔧 Debug
intermediate
2:00remaining
Identify the error in this LangChain chain execution
Given the following LangChain code snippet, what error will it raise when executed?
LangChain
from langchain.chains import SimpleSequentialChain, LLMChain
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate

llm = OpenAI(temperature=0)

prompt1 = PromptTemplate.from_template("Repeat: {input}")
chain1 = LLMChain(llm=llm, prompt=prompt1)

prompt2 = PromptTemplate.from_template("Again: {text}")
chain2 = LLMChain(llm=llm, prompt=prompt2)

final_chain = SimpleSequentialChain(chains=[chain1, chain2])

output = final_chain.run("Hello")
ATypeError: __init__() got an unexpected keyword argument 'llm'
BAttributeError: 'SimpleSequentialChain' object has no attribute 'run'
CValueError: Missing input key for chain execution
DRuntimeError: Chain execution failed due to empty chains list
Attempts:
2 left
💡 Hint
Check the constructor parameters for SimpleSequentialChain in LangChain.
component_behavior
intermediate
1:30remaining
What happens when a LangChain chain input key is missing?
Consider a LangChain chain expecting an input key 'question'. What happens if you run the chain with input {'query': 'What is AI?'} instead?
AThe chain runs successfully, ignoring the missing 'question' key
BThe chain returns None without error
CKeyError is raised indicating 'question' key is missing
DThe chain outputs an empty string as the result
Attempts:
2 left
💡 Hint
Chains require specific input keys to function properly.
state_output
advanced
2:00remaining
What is the output of this LangChain chain with a failing LLM call?
Given a LangChain chain that calls an LLM which raises an exception during execution, what will be the chain's output?
LangChain
from langchain.llms.base import LLM

class FailingLLM(LLM):
    def _call(self, prompt, stop=None):
        raise RuntimeError('LLM failure')

    @property
    def _identifying_params(self):
        return {}

    @property
    def _llm_type(self):
        return 'failing'

failing_llm = FailingLLM()

from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate

prompt = PromptTemplate(input_variables=['text'], template='Echo: {text}')
chain = LLMChain(llm=failing_llm, prompt=prompt)

try:
    output = chain.run('test')
except Exception as e:
    output = e.args[0]
AOutput is 'LLM failure'
BOutput is 'Echo: test'
COutput is None
DOutput is an empty dictionary {}
Attempts:
2 left
💡 Hint
Consider what happens when the LLM call raises an exception inside the chain.
📝 Syntax
advanced
1:30remaining
Which option correctly initializes a LangChain SequentialChain with two chains?
You want to create a SequentialChain that runs two chains in order. Which code snippet is correct?
ASequentialChain(chains=(chain1, chain2), input_vars=['input'], output_vars=['output'])
BSequentialChain(chains=[chain1, chain2], input_variables=['input'], output_variables=['output'])
CSequentialChain(chain1, chain2, input_vars=['input'], output_vars=['output'])
DSequentialChain([chain1, chain2], inputs=['input'], outputs=['output'])
Attempts:
2 left
💡 Hint
Check the parameter names and types in SequentialChain constructor.
🧠 Conceptual
expert
2:30remaining
Why does a LangChain chain fail silently when using an incorrect input key mapping?
You have a chain expecting input key 'question' but you pass {'query': 'Hello'}. The chain runs but returns an empty string without error. Why?
AThe LLM returns empty string for any input not matching 'question'
BLangChain automatically maps unknown keys to expected keys silently
CThe chain uses default empty string for missing keys and does not raise errors
DThe chain's prompt template uses the wrong variable name, causing empty output
Attempts:
2 left
💡 Hint
Consider how prompt templates use input variables and what happens if they don't match inputs.