langserve icon indicating copy to clipboard operation
langserve copied to clipboard

Add ability to translate exceptions

Open eyurtsev opened this issue 1 year ago • 8 comments
trafficstars

Expose exception translation capability to allow users to provide their own logic for translating server side errors into client side errors

https://github.com/langchain-ai/langserve/blob/e1cec832da29173df89bfe50b35be8ce59b1a8b5/langserve/api_handler.py#L1214-L1214

Discussed in https://github.com/langchain-ai/langserve/discussions/473

Originally posted by yw791772 February 21, 2024 Hi, I'm following the astream method in the langserve client code, and I have a try catch around the async sse code. For testing purpose, I use an api key that has no quota, and I can see the 429 errors from the langserve app logs. But when I looking at the decoded message from it on the client side, I only see 500 with internal server error.

Any guidance on how I can surface the 429 errors on the client side, so I can build specific around this error

eyurtsev avatar Feb 22 '24 15:02 eyurtsev

2 of the most common use cases I encountered:

  • 429 rate limiting
  • context too large, which could turn out to be hard to detect, for example: all I see is a 400 bad request from open ai

yw791772 avatar Feb 22 '24 20:02 yw791772

https://github.com/langchain-ai/langserve/discussions/545

eyurtsev avatar Mar 20 '24 12:03 eyurtsev

@eyurtsev do you have any ideas about how to approach implementing this? I can try to contribute a solution

philbo avatar Mar 21 '24 09:03 philbo

hii guys, any updates on this topic? or possible workaround?

ognjenAct avatar Jul 02 '24 08:07 ognjenAct

Hi, I am experiencing the same issue. Is there any workaround?

We are using Bedrock with on-demand throughput which often returns Throttling Exceptions with 429 error code and we need to return the error code to the UI, so an appropriate message can be displayed to the end user.

danielatchobanikova avatar Aug 12 '24 07:08 danielatchobanikova

I ended up working around it by implementing a custom APIHandler, then catching any exceptions raised by it and returning them in a basic JSON response with a 5xx status which the client can handle separately from the event stream.

philbo avatar Aug 28 '24 09:08 philbo