Skip to content

Commit 926fccb

Browse files
author
Andrei Bratu
committed
Custom error message for fancy functions decorated with tool
1 parent 2b0564f commit 926fccb

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/humanloop/decorators/tool.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,13 @@ def _build_tool_kernel(
116116
strict: bool,
117117
) -> ToolKernelRequestParams:
118118
"""Build ToolKernelRequest object from decorated function."""
119-
source_code = textwrap.dedent(inspect.getsource(func))
119+
try:
120+
source_code = textwrap.dedent(inspect.getsource(func))
121+
except TypeError as e:
122+
raise TypeError(
123+
f"Cannot extract source code for function {func.__name__}. "
124+
"Try decorating a plain function instead of a partial for example."
125+
) from e
120126
# Remove decorator from source code by finding first 'def'
121127
# This makes the source_code extraction idempotent whether
122128
# the decorator is applied directly or used as a higher-order

0 commit comments

Comments
 (0)