Experimental

Custom prompt checks

A custom prompt check blocks a tool call, or its result, if it matches a condition you write in natural language. You add one as a hook with the condition_check handler.

Custom prompt checks are available on paid plans, with usage-based pricing.

Here's a before_execute hook that stops your agent from sharing internal pricing with customers:

session = composio.create(
    user_id="user_123",
    hooks=[
        {
            "id": "no_pricing_to_customers",
            "type": "before_execute",
            "applies_to": {"toolkits": ["gmail"]},
            "handler": {
                "type": "condition_check",
                "condition": "Sharing internal pricing with anyone outside acme.com",
                "action": "block",
            },
        },
    ],
)

When your agent tries to email internal pricing to someone outside your company, the email isn't sent, and your agent sees the tool call fail with an error. See Blocked tool calls for what's returned when a hook blocks a tool call.

Here's an after_execute hook that keeps emails with passwords or API keys away from your agent:

session = composio.create(
    user_id="user_123",
    hooks=[
        {
            "id": "no_secrets_in_results",
            "type": "after_execute",
            "name": "No secrets in emails",
            "applies_to": {"toolkits": ["gmail"]},
            "handler": {
                "type": "condition_check",
                "condition": "An email that contains a password, API key or access token",
                "action": "block",
            },
        },
    ],
)

When Gmail returns an email with a password in it, your agent doesn't receive the email.

Use a before_execute hook to block something your agent is about to do, like emailing internal pricing to a customer. Use an after_execute hook to block something a tool returns before your agent reads it, like an email that contains a password or API key. An after_execute hook can't undo the tool call, since the tool has already run.

Writing a condition

It's important to write a condition as a description of the tool call or result you want blocked, not as an instruction for your agent to follow. A hook blocks a tool call or result when it matches the condition, and an instruction like "Don't share internal pricing with anyone outside acme.com" doesn't describe anything to match. Here are some good and bad ways to write a condition:

Good:

  • "Sharing internal pricing with anyone outside acme.com"
  • "An email that contains a password, API key or access token"

Bad:

  • "Don't share internal pricing with anyone outside acme.com"
  • "Hide emails that contain a password, API key or access token"

How we evaluate a condition

We use a decision model to compare each tool call to your condition. It sees which tool your agent is calling and the arguments it passes. In an after_execute hook, it also sees the data the tool returned.

The decision model also takes your agent's earlier activity in the session into account. This is important because a single tool call might seem harmless on its own, but when chained together with earlier tool calls, your agent might be doing something it's not allowed to do. For example, an email to a customer with a few numbers in it looks fine, unless your agent just copied those numbers from your internal pricing sheet.

For projects with ZDR enabled, we don't have context about your agent's historical activity, so our decision model can only judge a tool call in isolation. This may not work for certain kinds of checks.