Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import typing as t |
| 2 | |
| 3 | import pydantic |
| 4 | from composio_client import omit |
| 5 | |
| 6 | |
| 7 | def none_to_omit(value: t.Optional[t.Any]) -> t.Any: |
| 8 | """Convert None to omit for composio_client API calls. |
| 9 | |
| 10 | This utility function helps convert Python's None values to composio_client's |
| 11 | omit sentinel value, which tells the API to exclude the parameter entirely. |
| 12 | |
| 13 | Args: |
| 14 | value: Any value that might be None |
| 15 | |
| 16 | Returns: |
| 17 | The original value if not None, otherwise omit |
| 18 | |
| 19 | Example: |
| 20 | >>> none_to_omit("hello") |
| 21 | "hello" |
| 22 | >>> none_to_omit(None) |
| 23 | <omit> |
| 24 | >>> none_to_omit(42) |
| 25 | 42 |
| 26 | """ |
| 27 | return omit if value is None else value |
| 28 | |
| 29 | |
| 30 | def parse_pydantic_error(e: pydantic.ValidationError) -> str: |
| 31 | """Parse pydantic validation error.""" |
| 32 | message = "Invalid request data provided" |
| 33 | missing = [] |
| 34 | others = [""] |
| 35 | for error in e.errors(): |
| 36 | param = ".".join(map(str, error["loc"])) |
| 37 | if error["type"] == "missing": |
| 38 | missing.append(param) |
| 39 | continue |
| 40 | others.append(error["msg"] + f" on parameter `{param}`") |
| 41 | if len(missing) > 0: |
| 42 | message += f"\n- Following fields are missing: {set(missing)}" |
| 43 | message += "\n- ".join(others) |
| 44 | return message |