Business problem → AI workflow → governed output

AI-Powered CRM Request Automation

A detailed walkthrough of how a repetitive marketing audience request can move from manual analyst handling to an explainable, AI-assisted workflow—with query checks, sample output, auditability and human approval.

Marketing OperationsLLM-assisted codingSQL & DataHuman-in-the-loopAuditability
01

The marketing problem

CRM teams frequently need an audience extracted from a data platform so a campaign can be launched. When every request requires manual analyst handling, turnaround and analyst capacity become bottlenecks.

◷ Before: manual request handling

  • Marketing submits audience criteria on a request board.
  • An analyst interprets the request and opens the data platform.
  • The analyst writes or adapts SQL and checks exclusion criteria.
  • The output file is saved to a repository.
  • The analyst returns to the board to attach/comment and update status.

✦ After: AI-assisted workflow

  • Read and normalize the incoming request.
  • Compare the request against historical examples.
  • Reuse approved logic when the match is strong; otherwise draft a query for review.
  • Run validation checks and create a safe preview.
  • Prepare the output and board update while keeping a human approval gate.
Design principle: automate repeatable work, not accountability. The workflow can assist with matching, query drafting and orchestration, but audience logic and exclusions must still be verified before production delivery.
↗

Solution at a glance

A visual summary of how the request moves through the system—from a marketing need to a reviewed, auditable output.

1. RequestMarketing submits audience criteria in Monday.comStructured intake
2. Find contextCompare against historical requests and approved patternsKnowledge reuse
3. Draft logicReuse a safe template or draft SQL for analyst reviewAI-assisted
4. ValidateCheck filters, exclusions, preview and approvalHuman control
5. DeliverPrepare reviewed output and record the audit trailTraceable output
Decision gate: a strong historical match can accelerate reuse, but it does not bypass validation or human approval. A weak match goes to a review queue.

Before · Manual

  • ⌕Search old requests and query files manually
  • ⌨Rebuild or adapt SQL by hand
  • ↻Repeat checks and update request status
→

After · AI-assisted

  • ✦Retrieve relevant historical context
  • ⚙Draft or reuse logic with guardrails
  • ✓Review, record and return the result
02

End-to-end workflow

Select any step to highlight its role. The sequence mirrors a practical implementation: request intake, historical pattern matching, query generation, validation and output update.

01

Request intake

Capture request ID, campaign, audience description, inactivity window, country and exclusion rules from the request board.

Monday.com/APISchema validation
02

Understand & match

Compare structured fields with historical requests and approved query patterns. Keep the match score and reason explainable.

Historical repositoryCursor / LLM
03

Generate query

For a strong match, reuse approved logic. For a new pattern, draft a SELECT query and send it to review instead of blindly executing it.

SQL draftDatabricks Genie
04

Validate & review

Check query shape, exclusions, audience count and sample records. A designated reviewer verifies logic before production delivery.

GuardrailsHuman approval
05

Output & update

Save the approved audience output, record an audit event, and comment/update the original request board.

RepositoryAudit log

Step 1 — Request intake

The request is normalized into a consistent schema before any matching or query generation begins. Required fields and acceptable ranges are checked early so ambiguous requests do not silently progress.

Example request payload
{
  "request_id": "CRM-DEMO-001",
  "campaign": "Re-engagement",
  "inactive_days": 30,
  "country": "IN",
  "exclude_flagged_users": true
}
03

Decision logic: reuse or draft?

The most important decision is whether a request is sufficiently similar to a previously approved pattern. A partial match should not be treated as permission to auto-run a query.

High-confidence match

Key criteria match an approved historical example. Reuse its query template, bind the current values, and still require output review.

Reuse approved logicReview output
→

Controlled processing

Run static checks, preview audience counts, inspect exclusions, and prepare the request-board update only after checks pass.

No safe match

The request differs on an important attribute, or the repository does not contain a sufficiently similar approved pattern.

Draft onlyNo blind execution
→

Review queue

Draft a query for analyst review. The reviewer confirms business definitions, exclusions, table/column logic and expected audience size.

Why this matters: an LLM can generate plausible SQL that is still wrong. Historical matching, static checks, warehouse permissions and human review are separate layers—not substitutes for one another.
04

How the code components fit together

This maps the business flow to the project structure in the accompanying Python repository.

System architecture · conceptual view
Monday.comRequest intake OrchestrationParse + normalize Historical storeApproved patterns SQL assistanceTemplate / draft GuardrailsStatic checks Human reviewerBusiness logic + approval Reviewed outputPreview + audit + update Draft + validation result Reviewed status returned

Conceptual architecture, not a live integration map. In the demo scaffold, data and outputs are local; production connectors, warehouse execution, authentication and deployment remain separate implementation steps.

ComponentResponsibilityProduction consideration
app/main.pyAPI endpoints, request routing and dashboard serving.Add authentication, authorization, rate limits and request correlation IDs.
app/schemas.pyValidate required request fields and allowed value ranges.Use explicit business rules and reject ambiguous or incomplete requests.
app/matcher.pyCompare request attributes against approved historical patterns.Calibrate thresholds on labelled examples; monitor false matches and drift.
app/adapters.pyDemo query drafting, sample audience preview and request-board payload.Replace placeholders with approved LLM, warehouse and Monday.com adapters.
app/sql_guardrails.pyBasic static checks for the generated SQL draft.Static checks are not a security boundary; enforce read-only access and table allowlists at the data platform.
data/historical_requests.jsonStores example approved request patterns and templates.Version templates, track owners/approvals, and avoid storing sensitive audience data.
data/audit_log.jsonlRecords request status, match result and preview details.Use durable, access-controlled logging with retention and privacy controls.
05

Quality controls and human oversight

The objective is to reduce repetitive work while preserving data quality, privacy and accountability.

🛡️ Automated checks

  • Required request fields and value ranges.
  • Historical template match score and reason.
  • SQL draft checks: SELECT-only shape, one statement and LIMIT requirement.
  • Preview count and sample records using local demo data.
  • Audit event and request status payload.

👤 Human reviewer confirms

  • Business interpretation of the audience definition.
  • Correct inclusion and exclusion criteria.
  • Expected audience size and sample rows.
  • Permitted data sources and query performance.
  • Approval before any campaign delivery or live board update.
Demo limitation: this project uses local sample data. It does not call a real LLM, access Monday.com, or execute SQL in Databricks. The workflow illustrates the architecture and review controls; live integrations require separate credentials, permissions, testing and approval.
06

Business impact: what to measure

Use operational metrics to demonstrate whether automation actually creates capacity and improves service levels.

85–90%Initial testing accuracy reported in the project context. Validate against a labelled test set before making a performance claim.
TurnaroundMedian time from request submission to review-ready output, segmented by request type.
Analyst effortActive minutes spent per request before and after automation—not just elapsed time.
QualityFirst-pass approval rate, rework rate, exclusion errors and production incidents.
Example calculation: if median turnaround falls from 60 minutes to 15 minutes, elapsed turnaround is reduced by 75%. Measure analyst active time separately before claiming a 75% reduction in effort.
07

Interactive workflow demo

Submit a sample request to the local API and see the matching result, SQL draft, audience preview and review steps.

For this interactive form to work, run the Python API from the project folder with uvicorn app.main:app --reload. The dashboard alone can still be read as a static explanation.

Workflow result
Awaiting request

Submit the form to display the API response. This demonstration does not execute SQL against a live data platform.

SQL draft
-- The SQL draft will appear here