> ## 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.

# Find companies | Agent guide

> Resolve a target list, query a bounded segment, and save matching companies to your org.

[Human guide: task steps and agent prompt →](https://deepline.com/docs/human/recipes/search-free-companies.md)

> [!NOTE]
>
> Query a bounded free-company result and preserve its source identity before
> further enrichment.

Use the [free company search contract](https://deepline.com/docs/free-company-search-database.md) for
columns, limits, and snapshot semantics. These procedures query the shared
company snapshot. They do not perform live web discovery.

## Start from the CLI

Inspect `free_simple_company_search` for the live fields. Use a bounded
exact-domain query when your CRM or CSV already contains normalized domains:

```bash theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
PAYLOAD=$(cat <<'JSON'
{
  "sql": "SELECT normalized_domain, domain, company_name, industry, location, employee_count, year_founded FROM companies WHERE normalized_domain = 'openai.com' LIMIT 5"
}
JSON
)

deepline run free_simple_company_search --input "$PAYLOAD" --csv-out companies.csv
```

The direct command returns matching rows. `--csv-out` writes them to
CSV. It does not modify the Database or the shared snapshot.

## Practical SQL patterns

### Resolve and normalize a target list

Use lowercase hostnames matching `normalized_domain` in the `IN` list.
Preserve meaningful subdomains rather than collapsing them to another entity. The output gives you the snapshot's company name and LinkedIn URL
for review. It does not automatically overwrite CRM values.

```sql theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
SELECT normalized_domain, company_name, linkedin_url
FROM companies
WHERE normalized_domain IN ('openai.com', 'anthropic.com', 'vercel.com')
LIMIT 10
```

For a small list that already has LinkedIn company URLs, use exact equality or
`IN` as well:

```sql theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
SELECT company_name, normalized_domain, linkedin_url
FROM companies
WHERE linkedin_url IN ('linkedin.com/company/openai')
LIMIT 5
```

### Find candidates after an exact miss

Use a prefix only after an exact domain, LinkedIn URL, or company-name lookup
misses. Inspect the returned domain before using a candidate downstream:

```sql theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
SELECT company_name, normalized_domain, location, employee_count
FROM companies
WHERE company_name ILIKE 'acme%'
LIMIT 25
```

### Build a bounded pilot segment

Count the segment, then request a small page with the same filters.
Employee count is the upper bound of a source size bucket, not a live headcount.

```sql theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
SELECT COUNT(*) AS company_count
FROM companies
WHERE industry ILIKE '%software%'
  AND employee_count >= 50
  AND location ILIKE 'san francisco%'
  AND year_founded >= 2020
LIMIT 1
```

```sql theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
SELECT normalized_domain, company_name, industry, location, employee_count, year_founded
FROM companies
WHERE industry ILIKE '%software%'
  AND employee_count >= 50
  AND location ILIKE 'san francisco%'
  AND year_founded >= 2020
ORDER BY employee_count DESC
LIMIT 100
```

### Check coverage and source duplicates

Compare `matched_domains` with the number of unique normalized domains in your
input file. Unmatched domains do not appear in the result, so this tool cannot
label them as missing for you.

```sql theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
SELECT
  COUNT(*) AS source_records,
  COUNT(DISTINCT normalized_domain) AS matched_domains
FROM companies
WHERE normalized_domain IN ('openai.com', 'anthropic.com', 'vercel.com')
LIMIT 1
```

This query checks duplicate source records for the requested domains. It does
not detect duplicate rows in your CRM or CSV.

```sql theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
SELECT normalized_domain, COUNT(*) AS source_record_count
FROM companies
WHERE normalized_domain IN ('openai.com', 'anthropic.com', 'vercel.com')
GROUP BY normalized_domain
HAVING COUNT(*) > 1
LIMIT 20
```

> [accordion] Query from the API
>
> ## Query from the API
>
> Use the normal tool execution endpoint:
>
> ```bash theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
> curl -X POST "https://code.deepline.com/api/v2/integrations/free_simple_company_search/execute" \
>   -H "Authorization: Bearer $DEEPLINE_API_KEY" \
>   -H "Content-Type: application/json" \
>   --data-binary @- <<'JSON'
> {
>     "payload": {
>       "sql": "SELECT normalized_domain, company_name FROM companies WHERE normalized_domain = 'openai.com' LIMIT 5"
>     }
> }
> JSON
> ```
>
> The response wraps the SQL result in `data`:
>
> ```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
> {
>   "data": {
>     "schema": "public.companies",
>     "command": "SELECT",
>     "row_count_returned": 1,
>     "truncated": false,
>     "columns": [
>       { "name": "normalized_domain", "table_id": null, "data_type_id": null },
>       { "name": "company_name", "table_id": null, "data_type_id": null }
>     ],
>     "sql": "SELECT normalized_domain, company_name FROM companies WHERE normalized_domain = 'openai.com' LIMIT 5",
>     "executed_sql": "SELECT normalized_domain, company_name FROM COMPANIES WHERE normalized_domain = 'openai.com' LIMIT 5",
>     "limit": 5,
>     "rows": [{ "normalized_domain": "openai.com", "company_name": "OpenAI" }]
>   }
> }
> ```

> [accordion] Use inside a Play
>
> ## Use inside a Play
>
> Save this as `free-company-search.play.ts`. Read the declared `rows` list, then
> store it with `deepline.dataset` so the result can be exported as a run dataset.
>
> ```ts theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
> import deepline from 'deepline';
>
> export const config = {
>   description:
>     'Search the free company snapshot and return matching companies.',
> };
>
> export default async function () {
>   const result = await deepline.tools.execute({
>     id: 'free_company_search',
>     tool: 'free_simple_company_search',
>     input: {
>       sql: "SELECT normalized_domain, company_name, industry, location FROM companies WHERE location ILIKE 'san francisco%' LIMIT 100",
>     },
>     description: 'Find matching companies from the free company corpus.',
>     staleAfterSeconds: 0,
>   });
>
>   const companies = await deepline
>     .dataset('companies', result.extractedLists.rows.get())
>     .run();
>
>   return { companies, count: await companies.count() };
> }
> ```
>
> The result contains `companies`, a dataset with the four selected SQL columns,
> and `count`, its row count.
>
> Follow [Build a Play](https://deepline.com/docs/sdk-v2/plays.md#validate-before-deployment-or-spend) to check
> this source, then [Run Plays](https://deepline.com/docs/sdk-v2/calling-plays.md) to execute it and retain
> its run ID. Export the returned dataset with
> `deepline runs export <run-id> --dataset result.companies --out companies.csv`.

## Save matching companies to your org database

To save query results in your Database, use
`materialize_free_customer_companies`. It runs the SQL query and upserts rows
into `enrichments.companies`.

`domain` and `company_name` are required. The query can return only these
columns; the remaining fields are optional:

```txt theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
domain, company_name, industry, location, linkedin_url, employee_count, year_founded
```

Saving replaces the fields of an existing row with the same domain. Omitted
optional fields become null and can overwrite existing values. Review the
projected columns before saving.

Example:

```bash theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
PAYLOAD=$(cat <<'JSON'
{
  "sql": "SELECT normalized_domain AS domain, company_name, industry, location, linkedin_url, employee_count, year_founded FROM companies WHERE industry ILIKE '%software%' AND employee_count >= 50 LIMIT 1000"
}
JSON
)

deepline run materialize_free_customer_companies --input "$PAYLOAD"
```

Then query the saved rows with `query_customer_db`:

```bash theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
deepline run query_customer_db --input '{
  "sql": "SELECT domain, company_name, industry, employee_count FROM enrichments.companies ORDER BY updated_at DESC LIMIT 50"
}'
```

## Review a TAM sample before expanding it

Define the market's inclusion, exclusion, geography, and company entity before
querying. Count operating companies or parents consistently; duplicate source
records and subsidiaries can change a total without changing the market.
Retain the query, source scope, snapshot context, source IDs, and unresolved
domains with your export.

| Evidence | Sample disposition |
| - | - |
| Matched entity meets every inclusion rule | Qualified |
| Matched entity violates an explicit exclusion | Excluded, with the rule |
| Source size range crosses your segment threshold | Unresolved; do not invent an exact count |
| Source returns no company | Missing evidence, not verified non-fit |

The SQL counts describe this snapshot under your filters, not the entire
market. Enrich only fields needed by your inclusion rule, using
[company-field acceptance](https://deepline.com/docs/plays/task-enrich-company.md#accept-fields-separately) for entity and
headcount checks. Reconcile unique input domains against returned, excluded,
and unresolved accounts before saving or expanding the sample.

### Choose another source when a required field is absent

For TAM work, use this source when the ICP fits its documented fields:

* Exact domains or company names
* LinkedIn company URLs
* Industry or location
* Employee count or founding year

When the required signal is absent, inspect another supported source. Apollo
requires an explicitly selected customer-credential route. Do not assume
managed Apollo access.

## Verify this task

Check source identity, returned columns, duplicate scope, unmatched input domains, and inclusion decisions. Keep source queries separate from materialization writes.


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