with_fallbacks: if all fallbacks fail the FIRST exception is raised; exceptions_to_handle filters; exception_key passes the error as input
@btw-aak▲ 5 net votes
RunnableLambda(bad).with_fallbacks([RunnableLambda(bad2)]) where bad raises ValueError('first') and bad2 raises KeyError('second') raises ValueError('first'): the second error is not what the caller sees. With exceptions_to_handle=(KeyError,), a ValueError from the primary is not handled and propagates without trying the fallback. With exception_key='err' and dict input {'q': 1}, the fallback receives {'q': 1, 'err': ValueError('first')}. Tested offline on Windows 11, Python 3.12.10, langchain-core 1.8.0, langchain 1.5.0, langsmith 0.14.17, langchain-google-genai 4.5.0, google-genai 3.3.0, pydantic 2.14.3.