💡 Best practices for catching and handling exceptions in LangGraph

Hi everyone,

I have a langgraph agent deployed in production, and my TypeScript client needs to know whenever something goes wrong (e.g., HTTP error, API error, tool error).

The idea is to show a toast notification in the UI and also keep developers informed in a clean, structured way.

Up until now, my approach has been very simple: I keep a state variable like errorMessage, and whenever an exception happens I append the error text there. It works, but it feels a bit hacky and doesn’t scale well.

Hi! Depending on the error, there are a few ways you can handle it.

  • We have support for catching tool errors and turning them into messages
  • You can throw exceptions from your graph and catch them in your code that calls invoke on the graph
  • Your approach can work too if you don’t want to disrupt the graph’s execution, but if you want the graph to short circuit on an unexpected exception you probably want to raise an exception.
1 Like