Skip to content

The agent engineering platform.

Improve math chain error msg (#4415)

Zander Chase65f85af242c5
diff --git a/langchain/chains/llm_math/base.py b/langchain/chains/llm_math/base.py
index 1037658d60..b737b57f3f 100644
--- a/langchain/chains/llm_math/base.py
+++ b/langchain/chains/llm_math/base.py
@@ -84,7 +84,10 @@ class LLMMathChain(Chain):
)
)
except Exception as e:
- raise ValueError(f"{e}. Please try again with a valid numerical expression")
+ raise ValueError(
+ f'LLMMathChain._evaluate("{expression}") raised error: {e}.'
+ " Please try again with a valid numerical expression"
+ )
# Remove any leading and trailing brackets from the output
return re.sub(r"^\[|\]$", "", output)