@devries-cameron20 / composio-1 / commits / b39a10291
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(python): use inspect.cleandoc for docstring inference + add tests

Multi-line docstrings now have indentation properly stripped via inspect.cleandoc() instead of bare .strip(). Added tests for multi-line and indented docstrings. Slug inference: fn.__name__.upper() (e.g. search_users -> SEARCH_USERS) Name inference: fn.__name__ humanized (e.g. search_users -> Search Users) Description inference: inspect.cleandoc(fn.__doc__) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Dhawal Upadhyay committed Mar 23, 2026 at 17:52 UTC b39a102915038f340e8b85cdb690f81abf098f9f
2 files changed +31 -1
python/composio/core/models/custom_tool.py
+1 -1
@@ -240,7 +240,7 @@ def _infer_tool_from_function(
240 # Infer slug
241 actual_slug = slug or fn.__name__.upper()
242 actual_name = name or fn.__name__.replace("_", " ").title()
243 - actual_description = description or (fn.__doc__ or "").strip()
243 + actual_description = description or inspect.cleandoc(fn.__doc__ or "")
244
245 if not actual_description:
246 raise ValidationError(
python/tests/test_custom_tools.py
+30
@@ -166,6 +166,36 @@ class TestDecoratorTool:
166
167 assert my_func.description == "Trimmed docstring."
168
169 + def test_multiline_docstring(self):
170 + @exp.tool()
171 + def multi(input: GrepInput, ctx):
172 + """Search for users by email.
173 +
174 + This tool searches the internal database for users
175 + matching the given pattern. Returns a list of matches.
176 +
177 + Supports wildcards.
178 + """
179 + return {}
180 +
181 + assert multi.description.startswith("Search for users by email.")
182 + # inspect.cleandoc strips indentation
183 + assert "\n " not in multi.description
184 + assert "Supports wildcards." in multi.description
185 +
186 + def test_indented_docstring_cleaned(self):
187 + @exp.tool()
188 + def indented(input: GrepInput, ctx):
189 + """
190 + Leading and trailing whitespace removed.
191 + Indentation normalized.
192 + """
193 + return {}
194 +
195 + assert indented.description == (
196 + "Leading and trailing whitespace removed.\nIndentation normalized."
197 + )
198 +
199 def test_missing_docstring_raises(self):
200 with pytest.raises(ValidationError, match="description is required"):
201