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

# Route inbound leads | Agent guide

> Test a routing policy with known leads before changing CRM owners.

[Human guide: task steps and agent prompt →](https://deepline.com/docs/human/guides/inbound-lead-routing.md)

Produce owner proposals from an ordered decision table, then compare them with labeled examples before enabling CRM writes. The policy below is fictional customer-authored logic; replace its territories and owners with your own.

## Prepare the input and owner map

Use stable event and lead IDs plus the resolved CRM contact and company identity. Only accepted evidence should supply routing inputs. A failed lookup is an operational error, not an ineligible lead.

This synthetic `pilot.csv` uses a country code as its territory input:

```csv theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
event_id,lead_id,crm_contact_id,identity_status,eligible,country,current_owner,owner_protected
evt-1,lead-1,contact-1,resolved,true,US,,false
evt-2,lead-2,contact-2,resolved,true,GB,,false
evt-3,lead-3,contact-3,resolved,true,,,false
evt-4,lead-4,contact-4,resolved,true,US,owner-strategic,true
evt-5,lead-5,,ambiguous,true,US,,false
evt-6,lead-6,contact-6,resolved,false,US,,false
evt-7,lead-7,contact-7,resolved,true,CA,,false
```

In this example, eligibility has already been evaluated under the team's qualification and suppression policy. Keep unknown eligibility distinct from `false`.

Set the owner map to `US → owner-us` and `GB → owner-gb`. These are synthetic policy identifiers, not CRM owner IDs.

## Apply the first matching rule

| Order | Condition | Decision | Reason |
| - | - | - | - |
| 1 | Identity unresolved or conflicting | Hold | `identity_review` |
| 2 | Existing owner is protected | Preserve current owner | `protected_owner` |
| 3 | Eligibility unknown | Hold | `eligibility_unknown` |
| 4 | Eligibility false | No assignment | `ineligible` |
| 5 | Country missing | Hold | `territory_missing` |
| 6 | Exactly one territory and valid owner mapping | Propose mapped owner | `territory_match` |
| 7 | No territory, conflicting rules, or invalid mapping | Hold | `routing_policy_review` |

Under this table, `evt-1` proposes `owner-us`; `evt-2` proposes `owner-gb`; `evt-3` is held for missing territory; `evt-4` preserves `owner-strategic`; `evt-5` is held for identity review; `evt-6` receives no assignment; and `evt-7` is held because CA has no mapping. Add fixtures for unknown eligibility, overlapping territories, and a removed owner.

Return the evidence used, policy version, prior owner, proposed owner, and reason. For example:

```json theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
{
  "event_id": "evt-1",
  "lead_id": "lead-1",
  "crm_contact_id": "contact-1",
  "policy_version": "routing-example-v1",
  "decision": "propose",
  "current_owner": null,
  "proposed_owner": "owner-us",
  "reason": "territory_match",
  "evidence": {
    "identity_status": "resolved",
    "eligible": true,
    "country": "US"
  },
  "write_outcome": "not_attempted"
}
```

These are example output fields, not a built-in routing response schema. Resolve identity before evaluating territory and retain unknown or conflicting evidence for review.

## Inspect operations and run a proposal pilot

```bash theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
deepline auth status --json
deepline search "company domain -> account owner in CRM" --json
```

Inspect the returned contracts with `deepline describe <returned-id> --json`. Author `inbound-lead-routing.play.ts` from the table and owner map; [Build a Play](https://deepline.com/docs/sdk-v2/plays.md) covers source validation. Keep CRM writes disabled.

Prepare authorized `pilot.csv` rows with [CSV input](https://deepline.com/docs/sdk-v2/batch-csv.md). Review the source and expected Deepline usage before execution.

```bash theme={"languages":{"custom":["/languages/deepline-prompt.json"]}}
deepline plays check inbound-lead-routing.play.ts
deepline plays run --file inbound-lead-routing.play.ts --csv pilot.csv --watch
deepline runs get '<run-id>' --full --json
deepline runs export '<run-id>' --out inbound-lead-routing-review.csv
deepline billing usage --run-id '<run-id>' --json
```

Use the returned run ID and select a dataset path if several exist.

## Apply the HubSpot variant

Search `deepline search "HubSpot contact ID -> current contact owner" --json` and inspect the returned contracts. Resolve the existing contact ID, inspect property internal names and types, and read the available owners through supported actions.

Map each policy owner to a verified HubSpot owner ID. For example, `owner-us → 12345` is valid only if `12345` is an available owner in the target account. Confirm that the chosen update action accepts the `hubspot_owner_id` property and its value type. An owner name, email, or team label is not a substitute for the required ID. If the mapping is missing or invalid, hold the proposal.

Before an approved write, re-read the current owner and apply the protected-owner rule again. Submit only the authorized property, then read the contact back. Repeated events must reconcile the same intended assignment; a timeout after submission needs destination reconciliation before another attempt. [Repair CRM records](https://deepline.com/docs/guides/crm-data-quality-automation.md) covers field precedence, evidence records, and uncertain writes.

## Verify this task

Compare every row with the expected decisions above. Count proposed assignments, preserved owners, policy exceptions, and request failures separately.


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