Enrichment pipeline and rules
The enrichment pipeline turns a CRM record's website into company, contact, social, and industry data. It can run after a record is created or after a user starts it, then writes the result back to that record while keeping a traceable run history. The wider domain model is described in Domain enrichment.
Enrichment request lifecycle
An enrichment request is either a full background run or a small preview. The full run is the normal path: it protects the target record with permission checks, places one job on the long queue, and reports progress without making the user's save wait for network work.
Full enrichment run
The full run links one supported CRM record to one source website. A manual request reads the current website field, while an automatic request starts after insert when the feature and its record type are enabled. A per-record job identity prevents a manual click and an automatic trigger from starting duplicate work at the same time. crm/…/api.py• L39-74, crm/…/tasks.py• L100-154
The worker follows this sequence. It loads the current rules and mappings, runs the website pipeline, checks write access again, applies the result to the origin record, and records the outcome with any field changes.
flowchart LR
A[Website on CRM record] --> B[Manual or automatic trigger]
B --> C[Queued background job]
C --> D[Crawl website]
D --> E[Extract and classify]
E --> F[Map values to origin record]
F --> G[Save changed fields]
G --> H[Store run history and notify user]
The job treats progress reporting as optional. A failure does not escape as an untracked worker error: the job rolls back partial record changes when possible, writes a failed run, logs the detail, and sends an error event. crm/…/tasks.py• L159-265
References: crm/…/api.py• L39-74 crm/…/tasks.py• L100-154 crm/…/tasks.py• L159-265
References: crm/…/api.py• L39-74 crm/…/tasks.py• L100-154 crm/…/tasks.py• L159-265
Preview prefill
Preview is a separate, synchronous request for a create-record form. It reads only homepage metadata, such as JSON-LD, Open Graph, meta tags, favicon data, and declared social links. It does not crawl the site body, collect contacts, or classify industry. It returns mapped field values and notes without creating a document, a job, or a run. crm/…/api.py• L96-137, crm/…/pipeline.py• L25-100
References: crm/…/api.py• L96-137 crm/…/pipeline.py• L25-100
References: crm/…/api.py• L96-137 crm/…/pipeline.py• L25-100
Website crawling and extraction
The website stage converts a public website into a bounded set of pages and then into an explainable enrichment result. The crawler stays within the source site's registrable domain, follows configured depth and page limits, and gives useful company pages an earlier place in the queue.
Page discovery
The homepage is always the first page. If the crawl can continue, links from the site and optional sitemap entries add candidate pages at later depth. URL query strings and fragments do not create separate page identities. Skip patterns and file-type checks remove pages that are unlikely to contain company information. crm/…/crawler.py• L55-64, crm/…/crawler.py• L344-449
The page budget favors pages whose path or link text suggests company information. If no useful About page appears, the pipeline also tries a small set of common About paths while budget remains. This improves company descriptions without turning the crawl into an open-ended search. crm/…/config.py• L82-95, crm/…/crawler.py• L217-242, crm/…/pipeline.py• L145-158
References: crm/…/config.py• L82-95 crm/…/crawler.py• L217-242 crm/…/pipeline.py• L145-158
References: crm/…/config.py• L82-95 crm/…/crawler.py• L217-242 crm/…/pipeline.py• L145-158
Fetch safety
Every fetch accepts only HTTP or HTTPS and checks the host before connection. The fetch layer rejects non-public addresses, applies optional allowed and blocked domain lists, limits redirects, caps each download, and keeps non-HTML content out of normal page extraction. It repeats the safety check after each redirect. crm/…/http.py• L93-145, crm/…/http.py• L313-380
The crawler also respects robots.txt for discovered links when it performs a multi-page crawl. A missing or unreadable robots file does not stop the crawl. Request timeouts, retries, download size, and the user agent come from enrichment settings. crm/…/crawler.py• L185-215, crm/…/crm_enrichment_settings.json• L88-142
References: crm/…/http.py• L93-145 crm/…/http.py• L313-380 crm/…/crawler.py• L185-215 crm/…/crm_enrichment_settings.json• L88-142
References: crm/…/http.py• L93-145 crm/…/http.py• L313-380 crm/…/crawler.py• L185-215 crm/…/crm_enrichment_settings.json• L88-142
Extracted evidence
The extractor combines page metadata with visible page content. It can produce the following result groups:
| Result group | Main evidence | Purpose |
|---|---|---|
| Company identity | Organization JSON-LD, site metadata, and title | Company name, logo, and larger brand image |
| Company description | Organization metadata, About-page text, and homepage text | A short description of the company |
| Contacts | Email addresses and explicit phone links or phone-shaped text | Primary and secondary contact values |
| Social profiles | JSON-LD sameAs links and page links | Network URLs such as LinkedIn or GitHub |
| Industry | Headline text and configured industry rules | An industry label with a confidence value |
Each extracted scalar and contact keeps its source URL and extraction method. This lets a run reviewer distinguish declared metadata from body text, a link, a regular expression, or a keyword classification. crm/…/extractors.py• L364-403, crm/…/extractors.py• L453-503, crm/…/result.py• L18-100
References: crm/…/extractors.py• L364-403 crm/…/extractors.py• L453-503 crm/…/result.py• L18-100
References: crm/…/extractors.py• L364-403 crm/…/extractors.py• L453-503 crm/…/result.py• L18-100
Rule and field mapping configuration
Enrichment behavior is split into two kinds of configuration. Rules decide what a page signal means, while field mappings decide where a result may be written. The engine loads both from desk records for each full run, so an administrator can change the knowledge set without changing the extraction flow. crm/…/config.py• L234-270
Extraction rules
An enabled CRM Enrichment Rule groups one or more patterns under an Industry or Social rule type. A pattern can be a plain word or a regular expression. Its match scope tells the rule which evidence to inspect, and its weight controls the strength of an industry signal. crm/…/crm_enrichment_rule.json• L23-91, crm/…/crm_enrichment_rule_pattern.json• L8-28
Industry rules score matching signals and return a result only when the winning industry has enough score and a clear enough lead. Social rules map matching links to their configured network. Rule validation rejects duplicate targets, missing targets, and invalid regular expressions before a rule is saved. Default rules and the first set of industry records are seeded during install and migration, but existing administrator edits are not replaced. crm/…/crm_enrichment_rule.py• L52-92, crm/…/extractors.py• L71-80, crm/…/extractors.py• L569-644, crm/…/install.py• L275-285
References: crm/…/crm_enrichment_rule.json• L23-91 crm/…/crm_enrichment_rule_pattern.json• L8-28 crm/…/crm_enrichment_rule.py• L52-92 crm/…/extractors.py• L71-80 crm/…/extractors.py• L569-644 crm/…/install.py• L275-285
References: crm/…/crm_enrichment_rule.json• L23-91 crm/…/crm_enrichment_rule_pattern.json• L8-28 crm/…/extractors.py• L71-80 crm/…/extractors.py• L569-644 crm/…/install.py• L275-285
Field mappings
An enabled CRM Enrichment Field Mapping connects a result key to a field on a target CRM doctype. The supported result keys cover identity, description, logo, industry, primary and secondary contacts, and social networks. A mapping can be disabled without removing its rule or its target field. crm/…/crm_enrichment_field_mapping.json• L21-86, crm/…/mapper.py• L88-114
The write policy controls how fresh data interacts with existing CRM data:
| Policy | Effect on the target field |
|---|---|
Fill if empty | Write only when the field has no value |
Always refresh | Replace a stored value with a new non-empty value, but never clear it |
Override defaults | Replace only values listed as known defaults or an empty value |
Industry mappings can opt in to creating a missing linked industry. That creation still requires the active user to have create permission. Unknown target fields and failed linked-record creation are skipped instead of stopping the run. crm/…/mapper.py• L117-161, crm/…/mapper.py• L172-255
References: crm/…/crm_enrichment_field_mapping.json• L21-86 crm/…/mapper.py• L88-114 crm/…/mapper.py• L117-161 crm/…/mapper.py• L172-255
References: crm/…/crm_enrichment_field_mapping.json• L21-86 crm/…/mapper.py• L88-114 crm/…/mapper.py• L117-161 crm/…/mapper.py• L172-255
Crawl controls
CRM Enrichment Settings controls whether enrichment runs and how much work a run may do. The settings cover the master switch, supported record types, automatic triggers, page and depth limits, sitemap use, request limits, link order, skip patterns, and domain safety lists. An allow list limits fetches to listed domains and subdomains. A block list always wins and blocks its subdomains. crm/…/crm_enrichment_settings.json• L38-48, crm/…/crm_enrichment_settings.json• L93-213
The same settings gate both automatic and user-triggered work. The automatic path performs a cheap settings-only check at record creation, while the worker builds the full rule and mapping configuration only after the job starts. crm/…/config.py• L57-74, crm/…/tasks.py• L132-154
The frontend/…/EnrichmentSettings.vue page gives administrators one place to manage general availability and enrichment rules. It validates the crawl page limit before saving and keeps unsaved settings or rule changes visible until all requested updates succeed. frontend/…/EnrichmentSettings.vue• L1-55, frontend/…/EnrichmentSettings.vue• L119-247
References: crm/…/crm_enrichment_settings.json• L38-48 crm/…/crm_enrichment_settings.json• L93-213 crm/…/config.py• L57-74 crm/…/tasks.py• L132-154 frontend/…/EnrichmentSettings.vue• L1-55 frontend/…/EnrichmentSettings.vue• L119-247
References: crm/…/crm_enrichment_settings.json• L38-48 crm/…/crm_enrichment_settings.json• L93-213 crm/…/config.py• L57-74 crm/…/tasks.py• L132-154
Run results and history
An enrichment run is the durable record of one attempt against one CRM record and one source website. The system appends a new run for each attempt instead of changing an older result, which gives users a simple history of success and failure.
Run states
Runs use four states to show where the request is in its lifecycle:
| State | Meaning |
|---|---|
Queued | A request has been accepted for background work |
Running | The worker is crawling or processing the website |
Completed | The result was mapped and any changed origin fields were saved |
Failed | The attempt stopped and its error note was recorded |
Completed runs store summary values, counts of found emails and phones, social networks found, notes, and the full result JSON. The raw result includes page status, errors, notes, source URLs, and extraction methods. When the run changes a target field, the run also stores the old and new values as run-change rows. crm/…/crm_enrichment_run.json• L31-60, crm/…/tasks.py• L57-110, crm/…/crm_enrichment_run_change.py• L8-23, crm/…/result.py• L102-122
References: crm/…/crm_enrichment_run.json• L31-60 crm/…/tasks.py• L57-110 crm/…/crm_enrichment_run_change.py• L8-23 crm/…/result.py• L102-122
References: crm/…/crm_enrichment_run.json• L31-60 crm/…/tasks.py• L56-97 crm/…/result.py• L102-122
Progress feedback
The worker publishes record-scoped progress events for page discovery, crawling, extraction, classification, saving, and completion. The desk form listens only for events that match its current record, then reloads the record after success. A failed request leaves the record unchanged where rollback can remove partial writes and directs the user to the error log. crm/…/tasks.py• L26-53, crm/…/domain_enrichment.js• L26-79
References: crm/…/tasks.py• L26-53 crm/…/domain_enrichment.js• L26-79
References: crm/…/tasks.py• L26-53 crm/…/domain_enrichment.js• L26-79
Cross-record enrichment
Cross-record behavior copies stored enrichment from an already-enriched CRM Organization to a linked Lead or Deal. It is a synchronous link-time fill, not a second crawl, background fan-out, or write back to the Organization. crm/…/cross_record.py• L4-15
Organization source
The linked Organization is considered enriched when it has a completed enrichment run or populated native enriched fields. Its stored company name, description, logo, industry, and supported social links are wrapped as an enrichment result so the normal mapping authority can be reused. crm/…/cross_record.py• L30-76
References: crm/…/cross_record.py• L30-76
Lead and deal targets
When a Lead or Deal links an enriched Organization, the copy uses fill-empty behavior for every mapping. This rule is stricter than the normal run policy: even a mapping configured to refresh values cannot replace data that a user already entered. The copy is best effort and does not block the record save if the source is missing or the copy fails. crm/…/cross_record.py• L79-112, crm/…/crm_lead.py• L251-302, crm/…/crm_deal.py• L103-115
References: crm/…/cross_record.py• L79-112 crm/…/crm_lead.py• L251-302 crm/…/crm_deal.py• L103-115 crm/…/crm_deal.py• L209-219
User-triggered enrichment controls
Users can start enrichment from supported saved records and can retry an earlier run. The controls use the same background path as automatic enrichment, so the record receives the same crawl, mapping, history, and progress behavior.
Record enrichment action
The Enrich from Website action appears on saved CRM Leads, CRM Organizations, and CRM Deals. It requires a website and write permission on the record. The request is rate limited and is ignored as a duplicate when that record already has an in-flight job. crm/…/domain_enrichment.js• L9-23, crm/…/api.py• L25-60
References: crm/…/domain_enrichment.js• L9-23 crm/…/api.py• L25-60
Run retry action
The Retry Enrichment action appears on a run that points to a CRM record. It prefers that record's current website and falls back to the website stored on the old run. Retry creates a new run, which keeps the earlier attempt as history. crm/…/api.py• L77-93, crm/…/crm_enrichment_run.js• L3-17
References: crm/…/api.py• L77-93 crm/…/crm_enrichment_run.js• L3-17 crm/…/crm_enrichment_run.js• L20-63
Create-time automation
Automatic enrichment runs after insert when the master switch, the record-type switch, and the automatic setting are active and the new record has a website. The save does not wait for the crawl. The same per-record job identity makes an immediate manual action safe when an automatic request is already queued. crm/…/tasks.py• L132-154, crm/…/crm_organization.py• L31-38, crm/…/crm_lead.py• L100-109
References: crm/…/tasks.py• L132-154 crm/…/crm_organization.py• L31-38 crm/…/crm_lead.py• L100-109 crm/…/crm_deal.py• L106-115
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the source keys in
CRM Enrichment Field Mapping, result resolution, and seeded mappings aligned. A key that exists in only one of these layers silently produces no field value. - Keep the progress step count and labels aligned between the pipeline and desk progress display. A mismatch can show wrong progress even when the run succeeds.
- Preserve the shared mapper for both direct writes and Organization-to-Lead/Deal copies. Separate write logic can let cross-record copying overwrite user data.
- Review both manual and automatic gates when changing supported record types or settings. They must agree on the same doctype allow list.
- Treat changes to redirect handling, domain lists, or public-address checks as changes to the fetch safety contract for every user-supplied website.
- Keep run status, raw result storage, retry lookup, and the append-only history behavior aligned. A retry must point to the same target while creating a new history row.
- Keep run-change field names and old/new values aligned with mapper changes. A mismatch can make the run history disagree with the fields saved on the CRM record.
- Keep settings-page validation and server-side settings limits aligned. A client change that accepts a value the controller rejects can leave the page in an unsaved state.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A record has no website | The manual request is rejected and automatic enrichment does not start | Require a non-empty website before enqueueing |
| A website is blocked, unreachable, or too thin to read | The run records a note or failure and may have no mapped values | SSRF checks, bounded fetches, readability diagnosis, and failed-run recording |
| A redirect reaches a blocked or off-site host | The page is rejected instead of being used as evidence | Re-validate and pin every redirect hop; enforce same-site crawling |
| A rule has no valid compiled pattern | That rule contributes no result | Reject invalid regular expressions when a rule is saved |
| A rule target is duplicated or missing | The rule cannot be saved | Require a target and enforce one target per rule type |
| A mapped target field does not exist | That mapping is skipped | Check target metadata before writing |
| A mapped Link value names a missing record and creation is not allowed | The target field stays empty | Require explicit link creation and active-user create permission |
| A second request arrives while the same record is running | No second crawl is started | Use the per-record job identity and queue deduplication |
| Organization copy runs with user-filled target fields | User data remains unchanged | Force fill-empty policy for every cross-record copy |
| The settings page sends an invalid page limit | Settings do not save and the unsaved state remains visible | Validate whole numbers from 1 through the server limit before submit |
Key files
| File | Why to read it |
|---|---|
| crm/…/api.py | Public entry points for full enrichment, retry, and preview, including permission and rate limits |
| crm/…/tasks.py | Background job, progress events, run history writes, and automatic trigger rules |
| crm/…/pipeline.py | High-level sequence from website normalization through crawl, extraction, and classification |
| crm/…/crawler.py | Page scope, link discovery, sitemap use, robots handling, and crawl ordering |
| crm/…/extractors.py | The product-facing evidence types and the way descriptions, contacts, social links, and industry are selected |
| crm/…/config.py | The boundary between administrator-owned settings, rules, and field mappings |
| crm/…/mapper.py | The single write policy used for direct and cross-record enrichment |
| crm/…/cross_record.py | Organization-to-Lead/Deal copy behavior and its fill-empty contract |
| crm/…/result.py | Result shape, provenance, diagnostics, and raw history data |
| crm/…/crm_enrichment_settings.json | Admin controls for feature gates, crawl limits, ordering, skips, and domain safety |
| crm/…/crm_enrichment_rule.json | Rule types, match scopes, weights, and pattern groups |
| crm/…/crm_enrichment_rule.py | Rule validation for targets, duplicates, and regular expressions |
| crm/…/crm_enrichment_field_mapping.json | Result-to-field contracts and write policies |
| crm/…/crm_enrichment_run.json | Run states, summaries, diagnostics, and history fields |
| crm/…/crm_enrichment_run_change.py | Old and new values recorded for fields changed by a run |
| frontend/…/EnrichmentSettings.vue | Administrator view for general settings, page limits, and rule changes |
| crm/…/domain_enrichment.js | Saved-record action and live progress behavior |