Skip to main content

[ ![🦜️🔗 Langchain](/img/brand/wordmark.png) ![🦜️🔗
Langchain](/img/brand/wordmark-dark.png) ](/) [ Docs
](/docs/get_started/introduction) [ Use cases ](/docs/use_cases) [
Integrations ](/docs/integrations/platforms/) [ Guides
](/docs/guides/debugging) [ API  ](https://api.python.langchain.com)

More

  * [ People ](/docs/people/)
  * [ Versioning ](/docs/packages)
  * [ Changelog ](/docs/changelog)
  * [ Contributing ](/docs/contributing)
  * [ Templates ](/docs/templates/)
  * [ Cookbooks  ](https://github.com/langchain-ai/langchain/blob/master/cookbook/README.md)
  * [ Tutorials ](/docs/additional_resources/tutorials)
  * [ YouTube ](/docs/additional_resources/youtube)

🦜️🔗

  * [ LangSmith  ](https://smith.langchain.com)
  * [ LangSmith Docs  ](https://docs.smith.langchain.com/)
  * [ LangServe GitHub  ](https://github.com/langchain-ai/langserve)
  * [ Templates GitHub  ](https://github.com/langchain-ai/langchain/tree/master/templates)
  * [ Templates Hub  ](https://templates.langchain.com)
  * [ LangChain Hub  ](https://smith.langchain.com/hub)
  * [ JS/TS Docs  ](https://js.langchain.com)

[ 💬  ](https://chat.langchain.com) [ ](https://github.com/langchain-
ai/langchain)

Search

  * [ Debugging ](/docs/guides/debugging)
  * [ Deployment ](/docs/guides/deployments/)

  * [ Evaluation ](/docs/guides/evaluation/)

  * [ Extending LangChain ](/docs/guides/extending_langchain)
  * [ Fallbacks ](/docs/guides/fallbacks)
  * [ Run LLMs locally ](/docs/guides/local_llms)
  * [ Model comparison ](/docs/guides/model_laboratory)
  * [ Privacy ](/docs/guides/privacy/presidio_data_anonymization/)

  * [ Pydantic compatibility ](/docs/guides/pydantic_compatibility)
  * [ Safety ](/docs/guides/safety/)

  * [ [beta] Structured Output ](/docs/guides/structured_output)

  * [ ](/)
  * Debugging 

On this page

#  Debugging

If you're building with LLMs, at some point something will break, and you'll
need to debug. A model call will fail, or the model output will be
misformatted, or there will be some nested model calls and it won't be clear
where along the way an incorrect output was created.

Here are a few different tools and functionalities to aid in debugging.

##  Tracing  ​

Platforms with tracing capabilities like [ LangSmith ](/docs/langsmith/) and [
WandB ](/docs/integrations/providers/wandb_tracing) are the most comprehensive
solutions for debugging. These platforms make it easy to not only log and
visualize LLM apps, but also to actively debug, test and refine them.

For anyone building production-grade LLM applications, we highly recommend
using a platform like this.

![Screenshot of the LangSmith debugging interface showing an AgentExecutor run
with input and output details, and a run tree
visualization.](/assets/images/run_details-806f6581cd382d4887a5bc3e8ac62569.png)

##  ` set_debug ` and ` set_verbose ` ​

If you're prototyping in Jupyter Notebooks or running Python scripts, it can
be helpful to print out the intermediate steps of a Chain run.

There are a number of ways to enable printing at varying degrees of verbosity.

Let's suppose we have a simple agent, and want to visualize the actions it
takes and tool outputs it receives. Without any debugging, here's what we see:

    
    
    from langchain.agents import AgentType, initialize_agent, load_tools  
    from langchain_openai import ChatOpenAI  
      
    llm = ChatOpenAI(model_name="gpt-4", temperature=0)  
    tools = load_tools(["ddg-search", "llm-math"], llm=llm)  
    agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION)  
    
    
    
    agent.run("Who directed the 2023 film Oppenheimer and what is their age? What is their age in days (assume 365 days per year)?")  
    
    
    
        'The director of the 2023 film Oppenheimer is Christopher Nolan and he is approximately 19345 days old in 2023.'  
    

###  ` set_debug(True) ` ​

Setting the global ` debug ` flag will cause all LangChain components wi