Dosu LogoDosu Logo
Ask
Join our Discord
SurePublic
we-promise
DocumentsSure
Merchant Data Enhancement
Merchant Data Enhancement
Type
Topic
Status
Published
Created
Aug 5, 2026
Updated
Aug 5, 2026
Created by
Dosu Bot
Updated by
Dosu Bot

Merchant Data Enhancement#

Overview#

Merchant data enhancement is the process of enriching ProviderMerchant and FamilyMerchant records with website_url and logo_url fields. The two merchant subtypes use fundamentally different enrichment mechanisms: ProviderMerchant relies on an LLM pipeline triggered as an async job, while FamilyMerchant uses an automatic before_save callback that fires whenever a website URL is set.


ProviderMerchant: LLM-based Enrichment#

Pipeline Entry Point#

Enhancement is triggered via EnhanceProviderMerchantsJob, a medium_priority background job that accepts a family and calls ProviderMerchant::Enhancer.new(family).enhance . A cache key (enhance_provider_merchants:{family.id}) is cleared in an ensure block to prevent duplicate runs .

Enhancer Logic#

ProviderMerchant::Enhancer orchestrates the full pipeline:

  1. Target selection — fetches all ProviderMerchant records assigned to the family where website_url is blank .
  2. LLM call — sends merchants to Provider::Registry.preferred_llm_provider in batches of 25 via enhance_provider_merchants(merchants:, family:) . Both Provider::Anthropic and Provider::OpenAI implement this method with provider-specific strategies (tool-use vs. JSON schema).
  3. Update — for each merchant that the LLM returns a business_url for, website_url is written immediately. logo_url is also set via build_logo_url if Setting.brand_fetch_client_id is present .
  4. Deduplication — any other ProviderMerchant assigned to the family that shares the same website_url is treated as a duplicate: the family's transactions are re-pointed to the winning merchant . FamilyMerchant records are explicitly excluded from deduplication .

On-demand Logo Regeneration#

If a ProviderMerchant's website_url is manually corrected after the fact, generate_logo_url_from_website! can be called directly to rebuild the Brandfetch CDN URL. If website_url is blank, the method sets logo_url to nil .


FamilyMerchant: Automatic Callback Enrichment#

FamilyMerchant has no LLM step. Logo enrichment is handled entirely by a before_save callback: generate_logo_url_from_website runs whenever should_generate_logo? returns true — i.e., whenever website_url changes or website_url is present but logo_url is blank .

The callback builds the same Brandfetch CDN URL format as the ProviderMerchant pipeline, gated on Setting.brand_fetch_client_id . If website_url is cleared, logo_url is set to nil .

Because FamilyMerchant has no LLM pipeline, website_url must be supplied by the user (or copied from a ProviderMerchant during conversion). There is no automatic discovery of URLs for family-specific merchants.


Coverage Gap#

Merchant Typewebsite_url Sourcelogo_url SourceTriggered by
ProviderMerchantLLM (EnhanceProviderMerchantsJob)build_logo_url in Enhancer, or generate_logo_url_from_website!Async job per family
FamilyMerchantUser-supplied (or inherited from conversion)before_save callbackEvery save where URL changes

The practical consequence: ProviderMerchant records created without a website_url will remain logo-less until the enhancement job runs (and until the LLM can identify the business URL). FamilyMerchant records get logos automatically the moment website_url is written, but only if the user provides the URL in the first place.


Domain Extraction#

Both types strip the www. prefix before constructing CDN URLs. ProviderMerchant does this inside Enhancer#extract_domain and the instance method extract_domain on the model . FamilyMerchant has its own identical private extract_domain .


Key Files#

FileRole
app/jobs/enhance_provider_merchants_job.rbJob that kicks off LLM enrichment per family
app/models/provider_merchant/enhancer.rbCore LLM pipeline, deduplication, logo building
app/models/provider_merchant.rbgenerate_logo_url_from_website! for on-demand regeneration
app/models/family_merchant.rbbefore_save callback for automatic logo derivation

See also: Merchant Data Model article (STI structure and relationships), Brandfetch Logo Integration article (CDN URL format and client ID configuration).

Documents
Account Authorization and Permissions
Account Balance Calculation
Account Creation
Account Lifecycle Management
Account Provider Architecture
Account Reporting Controls
Account Statement Management
Account Statement Reconciliation
Account Type Architecture
AI Bank Statement Extraction
AI Chat Interface
API Authentication and Authorization
Authentication and Session Management
Balance History System
Banking Data Encryption
Banking Provider Integration
Brandfetch Logo Integration
Broker Activity Import
Budget Management
Category Management
Cryptocurrency Account Management
CSV Import and Column Mapping
Currency Management
Dashboard Filtering and Drilldowns
Depository Yield Modeling
Dev Container Setup
Dividend and DRIP Modeling
Docker Self-Hosting
Enable Banking Consent Management
Enable Banking Error Handling
Enable Banking OAuth and PSD2 Authentication
Entry Rendering
Family Data Export
Family Settings Management
Financial Insights and Metrics
Financial Reporting
FIRE Planning and Retirement Calculations
Goals and Savings Tracking
Internationalization and Localization
Investment Account Data Pipeline
Investment Account Flow Semantics
Investment Account Reconciliation
Investment Activity Labels
Investment Holdings Management
Investment Tax Treatment Classification
Investment Trade Conversion
Investment Trade Entry
Invitation Lifecycle and State Management
Ledger Entry Accounting Model
LLM Provider Configuration
LLM Request Timeout and Watchdog System
LLM Tool Calling
Manual Account Entry and Import
Manual Valuation
MCP Tool Access
Merchant Data Enhancement
Merchant Data Model
Multi-Currency Exchange Rates
NDJSON Import System
Net Worth Balance Sheet
OIDC Provider Configuration
Pending Transaction Reconciliation
Plaid Integration
Portfolio Cache and Price Resolution
Provider Import Adapter
Rails Development Environment Configuration
Rails PWA Integration
Recurring Transactions and Cash Flow Projection
REST API Architecture
Securities Lookup
Security Exchange Identification
Security Price Import Pipeline
SimpleFIN Holdings Import
SimpleFIN Integration
SimpleFIN Liability Balance Normalization
SnapTrade Integration
Split Transactions
SSO Audit Logging
SSO Authentication Flow
SSO Provider Management
Timezone-Aware Financial Data Handling
Transaction Categorization
Transaction Deduplication
Transaction Exclusion
Transaction Filtering and Search
Transaction Management
Transaction Name Resolution
Transaction Rule Engine
Transaction Sync Windows and Lookback
Transfer Management
Transfer Matching and Pairing
Turbo Frame Navigation
Yahoo Finance Integration
How split transaction child exclusion was implemented
Is it possible to edit the date of a synced transaction (e.g., one synced by LunchFlow)?
Provider Architecture