Skip to main content
If you’re building an agent, we recommend using sessions instead. See Tools and toolkits for how sessions handle tool discovery and execution automatically.
Before execution modifiers are part of Composio SDK’s powerful middleware capabilities that allow you to customize and extend the behavior of tools. These modifiers are called before the tool is executed by the LLM. This allows you to modify the arguments called by the LLM before they are executed by Composio. Useful for:
  • Injecting an argument into the tool execution
  • Overriding the arguments emitted by the LLM
Before Execution Modifier
Below we use the beforeExecute modifier to modify the number of posts returned by HACKERNEWS_GET_LATEST_POSTS.

With Chat Completions

Since completion providers don’t have a function execution step, Composio executes the tool call directly. The modifier is configured on the tools.execute method.

With Agentic Frameworks

Agentic providers have a function execution step. The modifier is configured on the tools.get method which modifies the execution logic within the framework.

Before file upload (Python)

For tools with file_uploadable parameters, the SDK can read a local path and upload the file before calling the Composio API. To audit, rewrite, or block those paths, use the @before_file_upload decorator and pass the decorated callables in modifiers to tools.get, tools.execute, or a tool router session’s tools(modifiers=...). See Executing tools: security for local file paths for constructor options, errors, and a full tabbed example. The hook takes either a single context argument (preferred) or the legacy 3-arg (path, tool, toolkit) form. The context object exposes context["source"] — "path" for local filesystem inputs and "url" for http(s)://... inputs — so you can scope audits to just local paths:
  • Composition: before_file_upload-type modifiers in the modifiers list are applied in list order (after filtering by each modifier’s tools / toolkits scope). Chaining works like a pipeline: each hook receives the path produced by the previous one.
  • Relative to before_execute: automatic file substitution runs before before_execute modifiers, matching TypeScript behavior (including tool router execute_meta).

Next

After execution modifiers