> ## Documentation Index
> Fetch the complete documentation index at: https://deepline.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Clarify: Run Query

> Run read-only SQL queries and aggregate reports over Clarify CRM workspace records. Includes inputs, outputs, SDK V2 examples, and Deepline cost.

Run read-only SQL queries and aggregate reports over Clarify CRM workspace records.

> [!NOTE]
>
> Tool ID: `clarify_run_query`

## Run this action

Use the TypeScript SDK for one call. Use `ctx.tools.execute(...)` inside a Play for durable calls, scheduled calls, or CSV processing.

```ts theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
import { Deepline } from 'deepline';

const deepline = await Deepline.connect();
const result = await deepline.tools.execute(
  'clarify_run_query',
  {
    "workspace": "example",
    "sql": "SELECT * FROM companies LIMIT 10"
  },
);

console.log(result.toolResponse.raw);
```

### CLI

```bash theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
deepline run clarify_run_query --input '{
  "workspace": "example",
  "sql": "SELECT * FROM companies LIMIT 10"
}'
```

## Example response

The SDK returns this shape at `result.toolResponse.raw`. The example values illustrate the response.

```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
{
  "data": {
    "data": [
      {}
    ],
    "links": {
      "next": "example",
      "prev": "example"
    },
    "meta": {
      "total_records": 123,
      "total_pages": 123,
      "offset": 123,
      "limit": 123
    }
  }
}
```

Use `deepline describe clarify_run_query --json` for the latest machine-readable contract.

## Input reference

Runs a read-only SQL query over the workspace’s records with the caller’s record access applied, and returns the rows as JSON with offset pagination in `links` and `meta`. A `LIMIT` or `OFFSET` in the SQL bounds the whole result, and `page[offset]` and `page[limit]` (up to 500) page within it. Each page reruns the query, so add an `ORDER BY` for stable pages. 64-bit integers, such as `COUNT(*)`, come back as strings to keep their precision.

| Name | Type | Required | Default | Details |
| - | - | - | - | - |
| `payload.workspace` | `string` | Yes | — | The workspace slug — the `&#123;slug&#125;` segment of your Clarify workspace URL. |
| `payload.page` | `object` | No | `&#123;"offset":0,"limit":500&#125;` | Offset pagination, e.g. `page[offset]=0&page[limit]=100`. |
| `payload.sortOrder` | `object` | No | — | Sort order, e.g. `sortOrder[column]=_created_at&sortOrder[dir]=DESC`. |
| `payload.silent` | `boolean` | No | — | When true, suppresses in-app and Slack notifications for this mutation. |
| `payload.sql` | `string` | Yes | — | A read-only PostgreSQL `SELECT` over the workspace’s objects. Each object is a table (`person`, `company`, `deal`, `c_*`) and its fields are columns. The query runs with the caller’s record access applied. Minimum length: 1. |

<details>
  <summary>Show raw input schema</summary>

  ### Input JSON Schema

  ```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
  {
    "type": "object",
    "description": "Runs a read-only SQL query over the workspace’s records with the caller’s record access applied, and returns the rows as JSON with offset pagination in `links` and `meta`. A `LIMIT` or `OFFSET` in the SQL bounds the whole result, and `page[offset]` and `page[limit]` (up to 500) page within it. Each page reruns the query, so add an `ORDER BY` for stable pages. 64-bit integers, such as `COUNT(*)`, come back as strings to keep their precision.",
    "properties": {
      "workspace": {
        "type": "string",
        "description": "The workspace slug — the `{slug}` segment of your Clarify workspace URL."
      },
      "page": {
        "type": "object",
        "description": "Offset pagination, e.g. `page[offset]=0&page[limit]=100`.",
        "default": {
          "offset": 0,
          "limit": 500
        },
        "properties": {
          "offset": {
            "type": "number",
            "description": "The number of records to skip before the first result.",
            "default": 0,
            "minimum": 0
          },
          "limit": {
            "type": "number",
            "description": "The maximum number of records to return per page (up to 500).",
            "default": 500,
            "minimum": 1,
            "maximum": 500
          }
        },
        "additionalProperties": false
      },
      "sortOrder": {
        "type": "object",
        "description": "Sort order, e.g. `sortOrder[column]=_created_at&sortOrder[dir]=DESC`.",
        "properties": {
          "column": {
            "type": "string",
            "description": "The field name to sort by.",
            "minLength": 1
          },
          "dir": {
            "type": "string",
            "description": "The sort direction.",
            "enum": [
              "ASC",
              "DESC"
            ]
          }
        },
        "required": [
          "column",
          "dir"
        ],
        "additionalProperties": false
      },
      "silent": {
        "type": "boolean",
        "description": "When true, suppresses in-app and Slack notifications for this mutation."
      },
      "sql": {
        "type": "string",
        "description": "A read-only PostgreSQL `SELECT` over the workspace’s objects. Each object is a table (`person`, `company`, `deal`, `c_*`) and its fields are columns; the query runs with the caller’s record access applied.",
        "minLength": 1
      }
    },
    "required": [
      "workspace",
      "sql"
    ],
    "additionalProperties": false
  }
  ```
</details>

## Output reference

Standard tool result payload.

| Name | Type | Required | Default | Details |
| - | - | - | - | - |
| `result.data` | `object` | Yes | — | Provider response payload. |
| `result.data.data` | `array` | Yes | — | The result rows, one object per row keyed by column name. 64-bit integers, such as `COUNT(*)`, are strings. |
| `result.data.links` | `object` | Yes | — | — |
| `result.data.links.next` | `string \| null` | Yes | — | The URL of the next page of rows, or null on the last page. |
| `result.data.links.prev` | `string \| null` | Yes | — | The URL of the previous page of rows, or null on the first page. |
| `result.data.meta` | `object` | Yes | — | — |
| `result.data.meta.total_records` | `number` | Yes | — | The number of rows the query matches across all pages. |
| `result.data.meta.total_pages` | `number` | Yes | — | The number of pages at this page size. |
| `result.data.meta.offset` | `number` | Yes | — | The number of rows skipped before this page. |
| `result.data.meta.limit` | `number` | Yes | — | The maximum number of rows on a page. |
| `result.meta` | `object` | No | — | Additional response metadata (status, paging). |

<details>
  <summary>Show raw output schema</summary>

  ### Output JSON Schema

  ```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
  {
    "type": "object",
    "description": "Standard tool result payload.",
    "properties": {
      "data": {
        "type": "object",
        "description": "Provider response payload.",
        "properties": {
          "data": {
            "type": "array",
            "description": "The result rows, one object per row keyed by column name. 64-bit integers, such as `COUNT(*)`, are strings.",
            "items": {
              "type": "object",
              "additionalProperties": {}
            }
          },
          "links": {
            "type": "object",
            "properties": {
              "next": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "The URL of the next page of rows, or null on the last page."
              },
              "prev": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "The URL of the previous page of rows, or null on the first page."
              }
            },
            "required": [
              "next",
              "prev"
            ],
            "additionalProperties": false
          },
          "meta": {
            "type": "object",
            "properties": {
              "total_records": {
                "type": "number",
                "description": "The number of rows the query matches across all pages."
              },
              "total_pages": {
                "type": "number",
                "description": "The number of pages at this page size."
              },
              "offset": {
                "type": "number",
                "description": "The number of rows skipped before this page."
              },
              "limit": {
                "type": "number",
                "description": "The maximum number of rows on a page."
              }
            },
            "required": [
              "total_records",
              "total_pages",
              "offset",
              "limit"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "data",
          "links",
          "meta"
        ],
        "additionalProperties": false
      },
      "meta": {
        "type": "object",
        "description": "Additional response metadata (status, paging).",
        "additionalProperties": true
      }
    },
    "required": [
      "data"
    ],
    "additionalProperties": false
  }
  ```
</details>

## Deepline cost

* Pricing model: `fixed` (per call).
* Estimated Deepline credits: `0` per pricing unit.
* Provider-native pricing may still exist outside Deepline credit billing.

## Related documentation

* [Connect integrations](https://deepline.com/docs/integrations.md)
* [SDK V2 quickstart](https://deepline.com/docs/sdk-v2/quickstart.md)
* [SDK reference](https://deepline.com/docs/sdk-v2/sdk-reference.md)
* [Run tools across a CSV](https://deepline.com/docs/sdk-v2/batch-csv.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.