Skip to main content
Data Engineering9 min read

Model for the Token, Not the Table: Data Modeling as an AI Cost-Control Strategy

AI cost control is becoming a data architecture problem. A dbt case study shows how modeling Gong transcripts in the warehouse reduced token costs by 20x, highlighting why modernization teams should treat modeling, lineage, and governance as core AI infrastructure.

LLM costs rarely explode because a team wrote one bad prompt. They explode because every prompt drags too much messy, duplicated, irrelevant, or poorly structured data into the context window.

That is why one of the most important AI engineering lessons right now sounds like classic data engineering: model the data before you send it to the model.

The new cost center hiding in your data layer

Model for the Token, Not the Table: Data Modeling as an AI Cost-Control Strategy
Model for the Token, Not the Table: Data Modeling as an AI Cost-Control Strategy

For years, engineering teams optimized databases around query performance, storage cost, reporting accuracy, and operational reliability. Now there is another constraint: tokens.

Every transcript, support ticket, product event, and CRM note that gets passed into an LLM has a cost. It also affects latency, retrieval quality, and answer reliability. The larger and noisier the context, the more expensive and less predictable the AI workflow becomes.

This is the core argument in dbt’s article, Model for the token, not the table. The post describes a team that was burning through Gong’s API to feed AI workflows. Instead of repeatedly calling Gong and pushing raw or semi-structured transcript data into AI prompts, they modeled the transcripts in the warehouse with dbt. The result: token costs dropped by 20x.

That is not just a prompt optimization story. It is a modernization story.

The team did not solve the problem by swapping models, adding a clever cache, or asking developers to write shorter prompts. They solved it by improving the shape, governance, and accessibility of the underlying data. In other words, the AI system became cheaper because the data system became better maintained.

Why token cost is really an architecture problem

A token budget is a design constraint. If your AI workflow summarizes sales calls, extracts customer objections, generates account intelligence, or powers an internal agent, it needs context. But context is only useful when it is relevant, compact, and trustworthy.

Raw operational data is rarely any of those things.

Call transcripts may include greetings, filler words, repeated names, timestamp artifacts, bot messages, and irrelevant chatter. CRM notes may be inconsistent. Support histories may span years and include outdated product behavior. Product analytics may use event names that changed three times across different versions of an application.

When AI features consume this data directly, three bad things happen:

  1. Costs rise because prompts include unnecessary text.
  2. Quality drops because useful signals are buried in noise.
  3. Reliability suffers because the system cannot distinguish current, governed facts from stale or duplicate information.

Traditional data modeling addresses exactly these problems. Transformations remove noise. Business logic standardizes meaning. Lineage explains where data came from. Tests catch unexpected changes. Documentation helps teams understand what each field represents.

The difference is that the downstream consumer is no longer only a dashboard or analyst. It is also an LLM, an agent, a retrieval pipeline, or an AI feature embedded in a product.

What the Gong transcript example teaches

The Gong example from dbt is useful because it is concrete. Many teams are building AI workflows around sales calls, customer conversations, and account data. The obvious first implementation is to call the source API, fetch transcripts, and hand them to the LLM.

That works for a demo. It often fails at scale.

Repeatedly pulling source data from an API creates operational fragility. Sending full transcripts into prompts burns tokens. Asking each application team to clean and summarize the same data creates duplicated logic. And if the source schema changes, multiple AI workflows may break in different ways.

By moving transcript modeling into the warehouse with dbt, the team created a reusable layer between the source system and the AI workflow. Instead of feeding the LLM raw transcripts, they could feed it curated, structured, and purpose-built representations of the conversation.

For example, a modeled transcript layer might include:

  • Speaker-separated conversation turns
  • Cleaned text with filler and artifacts removed
  • Standardized timestamps and call metadata
  • Extracted topics, objections, competitors, and next steps
  • Account, opportunity, and contact joins
  • Summaries at different levels of detail
  • Flags for sensitive or low-confidence content

This lets an AI workflow retrieve the right slice of context instead of the entire conversation. It also lets teams reuse the same modeled data across sales coaching, customer intelligence, churn analysis, onboarding, and executive reporting.

The 20x token reduction matters because it shows that AI cost control is not only about choosing a cheaper model. It is about reducing waste before inference happens.

Agent reliability starts before the agent

In a related dbt article, Why agentic projects fail and how to fix them, dbt argues that many agentic AI projects fail because of issues in the underlying data. That point should resonate with anyone who has maintained production software systems.

Agents are only as reliable as the tools and data they use. If an agent queries inconsistent metrics, outdated customer records, undocumented tables, or conflicting definitions of revenue, it will produce confident but unreliable output. The failure may look like an AI problem, but the root cause is often a data maintenance problem.

This is especially important for CTOs and modernization leaders. Many organizations are layering AI features on top of systems that were not designed for AI consumption. Legacy databases, SaaS exports, event streams, and manual spreadsheets may all feed the same retrieval pipeline. Without a governed modeling layer, the agent has to reason over chaos.

That is not a fair job for the model.

A modern AI stack needs a semantic and operational contract between enterprise data and AI applications. dbt-style modeling helps create that contract by defining transformations, tests, documentation, ownership, and lineage in code. Recent dbt Core releases, including the v1.12 GA announcement, continue to reinforce the importance of maintainable transformation workflows for analytics and AI-adjacent use cases.

Model for consumption, not just storage

The phrase “model for the token, not the table” is powerful because it challenges a long-standing habit. Database tables are often designed around source systems, normalization, reporting needs, or ingestion convenience. AI systems need something different: context objects.

A context object is the information package an AI workflow actually needs to complete a task. It may combine multiple tables, include derived fields, remove irrelevant details, and compress long histories into structured summaries.

For a customer-success agent, the right context object might include current plan, renewal date, open support issues, recent usage trends, last executive interaction, and known risks. It probably does not need every raw clickstream event or every ticket comment.

For a code modernization assistant, the right context might include service ownership, dependency maps, runtime versions, recent incidents, deprecated libraries, and architectural decision records. It does not need every line of every log file.

For a sales call summarizer, the right context might include the cleaned transcript, identified speakers, opportunity stage, account segment, and prior call summary. It does not need the entire CRM export.

This shift requires engineering teams to ask different modeling questions:

  • What decision or action will the AI system support?
  • What is the minimum context needed to support that action?
  • Which fields are authoritative?
  • Which data should be excluded for privacy, cost, or quality reasons?
  • How should context be versioned and tested?
  • How will we know if the context has drifted?

Those are data engineering questions, but they are now also AI product questions.

Practical implications for modernization teams

For teams modernizing applications and adding AI capabilities, the lesson is straightforward: do not bolt AI directly onto brittle data flows.

Instead, treat AI adoption as an opportunity to improve the data architecture around your systems. At Vibgrate, we see this pattern across modernization efforts: teams that understand their dependencies, data contracts, ownership boundaries, and upgrade paths are better positioned to add reliable automation. AI does not remove the need for maintenance discipline. It raises the value of it.

Here are practical steps engineering leaders can take.

1. Audit AI workflows for token waste

Look at your highest-volume AI use cases. Identify what data is being passed into prompts or retrieval pipelines. Then ask how much of that context is actually used.

Common waste patterns include full transcripts when summaries would work, entire documents when specific sections are needed, duplicated records across joins, and raw event streams when aggregates would be enough.

2. Create modeled AI-ready datasets

Do not make every AI feature team clean the same data in application code. Build reusable modeled datasets in the warehouse. Use transformation tools such as dbt to create tested, documented layers for common AI contexts: customers, accounts, conversations, incidents, services, dependencies, and product usage.

3. Add lineage and ownership

When an AI output is wrong, teams need to debug the data path. Where did the context come from? Which transformation changed it? Who owns the definition? Lineage turns AI troubleshooting from guesswork into engineering work.

4. Design for retrieval quality

Retrieval is not only a vector database problem. Chunking, metadata, filtering, freshness, and semantic consistency all depend on upstream modeling. Better-modeled data leads to better retrieval, which leads to better answers with fewer tokens.

5. Govern sensitive and stale data

AI workflows can accidentally expose information that should not be in a prompt. Modeling layers give teams a place to redact, filter, classify, and enforce policies before data reaches the model.

6. Treat token budgets like performance budgets

Engineering teams already manage latency, memory, cloud spend, and database query cost. Token usage should be monitored the same way. Define budgets per workflow, track regressions, and make context size visible in code reviews and release checks.

The modernization takeaway

The teams that succeed with AI will not be the ones that send the most data to the largest model. They will be the ones that send the right data, in the right shape, at the right time.

The Gong transcript example shows that disciplined data modeling can produce dramatic AI cost reductions. The broader dbt argument about agentic failures reinforces the same point: AI reliability depends on the quality of the systems beneath it.

For developers, this means data transformations, tests, and documentation are now part of AI engineering. For CTOs, it means modernization roadmaps should connect application upgrades, data governance, and AI adoption instead of treating them as separate initiatives.

Modeling for the token is not a temporary optimization. It is a durable architecture principle for the next generation of software systems.

Vibgrate CLI

See a real scan run

A replay of the actual CLI running against our test repositories — live progress, real findings, a genuine DriftScore. Nothing executes in your browser.

Replay
demo@vibgrate — bash
npx @vibgrate/cli scan
 
╭──────────────────────────────────────────╮
Vibgrate Drift Report
╰──────────────────────────────────────────╯
 
── node-turborepo (node) .
Runtime: >=18.0.0 (6 majors behind)
Frameworks:
Turbo: 1.13.4 → 2.10.11 (1 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Dependencies:
1 current 1 1-behind 3 2+ behind 1 unknown
 
── @repo/admin (node) apps/admin
Frameworks:
TanStack Query: 5.101.4 → 5.101.4 (current)
React: 18.3.1 → 19.2.8 (1 behind)
React DOM: 18.3.1 → 19.2.8 (1 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Vite: 5.4.21 → 8.2.1 (3 behind)
Dependencies:
3 current 9 1-behind 3 2+ behind 4 unknown
 
── @repo/api (node) apps/api
Frameworks:
Express: 4.22.2 → 5.2.1 (1 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Vitest: 1.6.1 → 4.1.11 (3 behind)
Dependencies:
7 current 5 1-behind 3 2+ behind 4 unknown
 
── @repo/web (node) apps/web
Frameworks:
Next.js: 14.2.35 → 16.3.1 (2 behind)
React: 18.3.1 → 19.2.8 (1 behind)
React DOM: 18.3.1 → 19.2.8 (1 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Dependencies:
2 current 6 1-behind 3 2+ behind 5 unknown
 
── @repo/config (node) packages/config
Frameworks:
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Dependencies:
2 current 2 1-behind 5 2+ behind 0 unknown
 
── @repo/database (node) packages/database
Frameworks:
Prisma: 5.22.0 → 7.9.1 (2 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Dependencies:
1 current 0 1-behind 3 2+ behind 1 unknown
 
── @repo/types (node) packages/types
Frameworks:
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Dependencies:
0 current 0 1-behind 1 2+ behind 1 unknown
 
── @repo/ui (node) packages/ui
Frameworks:
React: 18.3.1 → 19.2.8 (1 behind)
TypeScript: 5.9.3 → 7.0.2 (2 behind)
React: 18.3.1 → 19.2.8 (1 behind)
Dependencies:
1 current 4 1-behind 1 2+ behind 1 unknown
 
── @repo/utils (node) packages/utils
Frameworks:
TypeScript: 5.9.3 → 7.0.2 (2 behind)
Vitest: 1.6.1 → 4.1.11 (3 behind)
Dependencies:
0 current 1 1-behind 2 2+ behind 1 unknown
 
Tech Stack
Frontend: React, React DOM
Meta-frameworks: Next.js
Bundlers: tsx, Turbo, Vite
CSS / UI: Autoprefixer, PostCSS, Tailwind CSS
Backend: Express
ORM / Database: Prisma, Prisma Client
Testing: Vitest
Lint & Format: ESLint, ESLint Prettier, ESLint React, Prettier, typescript-eslint
 
Services & Integrations
Auth: JWT 9.0.3
Databases: Prisma 5.22.0
 
TypeScript
v5.3.3 · strict ✔ · MIXED · target: ES2022
 
Build & Deploy
Package Managers: pnpm
Monorepo: npm-workspaces, pnpm-workspaces, turbo
 
Product Purpose Signals
Frameworks: react, nextjs
Evidence: 177
Top Signals:
- [heading] Dashboard (apps/admin/src/pages/Dashboard.tsx)
- [title] Revenue Overview (apps/admin/src/pages/Dashboard.tsx)
- [copy] workspace:* (packages/ui/package.json)
- [copy] ./dist (packages/ui/tsconfig.json)
- [copy] ./src/index.ts (packages/ui/package.json)
- [copy] @repo/config/tsconfig-base.json (packages/ui/tsconfig.json)
- [copy] @repo/ui (packages/ui/package.json)
- [copy] #3b82f6 (apps/admin/src/pages/Dashboard.tsx)
Unknowns:
- No pricing or billing evidence found.
- No integrations/connectors evidence found.
- No route structure evidence found.
 
Security Posture
Lockfile ✖ · .env ✔ · node_modules ✔
 
Platform
Native modules: turbo
 
Code Quality
Files: 36 · Functions: 183 · Avg complexity: 2.62 · Avg length: 21.13 lines
Max nesting: 2 · Circular deps: 0 · Dead code: 0%
God files: apps/admin/src/pages/Products (448 lines)
 
Database Schema
postgresql · 8 models · 1 enum
Models: Address, CartItem, Category, Order, OrderItem (+3 more)
 
Findings (16 errors, 11 warnings)
Node.js runtime ">=18.0.0" reached end-of-life on 2025-04-30 (latest: 24.0.0).
vibgrate/runtime-eol in .
TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in .
60% of dependencies are 2+ major versions behind in node-turborepo.
vibgrate/dependency-rot in .
@types/node is 6 major versions behind (spec: ^20.11.0, latest: 26.2.0).
vibgrate/dependency-major-lag in .
TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in apps/admin
Vite is 3 major versions behind (current: 5.4.21, latest: 8.2.1).
vibgrate/framework-major-lag in apps/admin
vite is 3 major versions behind (spec: ^5.0.12, latest: 8.2.1).
vibgrate/dependency-major-lag in apps/admin
TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in apps/api
Vitest is 3 major versions behind (current: 1.6.1, latest: 4.1.11).
vibgrate/framework-major-lag in apps/api
@types/node is 6 major versions behind (spec: ^20.11.0, latest: 26.2.0).
vibgrate/dependency-major-lag in apps/api
vitest is 3 major versions behind (spec: ^1.2.1, latest: 4.1.11).
vibgrate/dependency-major-lag in apps/api
Next.js is 2 major versions behind (current: 14.2.35, latest: 16.3.1).
vibgrate/framework-major-lag in apps/web
TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in apps/web
@types/node is 6 major versions behind (spec: ^20.11.0, latest: 26.2.0).
vibgrate/dependency-major-lag in apps/web
TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in packages/config
56% of dependencies are 2+ major versions behind in @repo/config.
vibgrate/dependency-rot in packages/config
eslint-plugin-react-hooks is 3 major versions behind (spec: ^4.6.0, latest: 7.1.1).
vibgrate/dependency-major-lag in packages/config
Prisma is 2 major versions behind (current: 5.22.0, latest: 7.9.1).
vibgrate/framework-major-lag in packages/database
TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in packages/database
75% of dependencies are 2+ major versions behind in @repo/database.
vibgrate/dependency-rot in packages/database
TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in packages/types
100% of dependencies are 2+ major versions behind in @repo/types.
vibgrate/dependency-rot in packages/types
TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in packages/ui
TypeScript is 2 major versions behind (current: 5.9.3, latest: 7.0.2).
vibgrate/framework-major-lag in packages/utils
Vitest is 3 major versions behind (current: 1.6.1, latest: 4.1.11).
vibgrate/framework-major-lag in packages/utils
67% of dependencies are 2+ major versions behind in @repo/utils.
vibgrate/dependency-rot in packages/utils
vitest is 3 major versions behind (spec: ^1.2.1, latest: 4.1.11).
vibgrate/dependency-major-lag in packages/utils
 
╭──────────────────────────────────────────╮
Top Priority Actions
╰──────────────────────────────────────────╯
 
1. Upgrade EOL runtime in node-turborepo
End-of-life runtimes no longer receive security patches and block ecosystem upgrades.
./.
>=18.0.0 → 24.0.0 (6 majors behind)
Impact: −10 drift points (runtime & EOL)
 
2. Fix security posture: no lockfile found
Without a lockfile, installs are non-deterministic. Run the install command to generate one and commit it.
./
Missing: package-lock.json, pnpm-lock.yaml, or yarn.lock
 
3. Upgrade Vite 5.4.21 → 8.2.1 in @repo/admin (+2 more)
3 major versions behind. Major framework drift increases breaking change risk and blocks access to security fixes and performance improvements.
./apps/admin
Vite: 5.4.21 → 8.2.1 (3 majors behind)
./apps/api
Vitest: 1.6.1 → 4.1.11 (3 majors behind)
./packages/utils
Vitest: 1.6.1 → 4.1.11 (3 majors behind)
Impact: −5–15 drift points
 
4. Reduce dependency rot in @repo/types (100% severely outdated)
1 of 1 dependencies are 2+ majors behind. Run `npm outdated` and prioritise packages with known CVEs or breaking API changes.
./packages/types
typescript: 5.9.3 → 7.0.2 (2 majors behind)
Impact: −5–10 drift points
 
5. Reduce dependency rot in @repo/database (75% severely outdated)
3 of 4 dependencies are 2+ majors behind. Run `npm outdated` and prioritise packages with known CVEs or breaking API changes.
./packages/database
@prisma/client: 5.22.0 → 7.9.1 (2 majors behind)
prisma: 5.22.0 → 7.9.1 (2 majors behind)
typescript: 5.9.3 → 7.0.2 (2 majors behind)
Impact: −5–10 drift points
 
╭──────────────────────────────────────────╮
Architecture Layers
╰──────────────────────────────────────────╯
 
Archetype: nextjs (80% confidence)
Files classified: 24 (11 unclassified)
Folders classified: 8
apps/admin/src presentation 100% 4 files
apps/admin/src/pages presentation 100% 2 files
apps/api/src/middleware middleware 100% 2 files
apps/api/src/routes routing 100% 2 files
apps/web/src/app presentation 100% 4 files
apps/web/src/app/products presentation 100% 2 files
apps/web/src/app/products/[id] presentation 100% 1 file
packages/ui/src presentation 100% 6 files
Unclassified source (sample): 11
 
presentation 15 files drift ████████████████████ 100 risk high
routing 4 files drift ████████████████████ 100 risk high
middleware 2 files drift ███████▍░░░░░░░░░░░░ 37 risk moderate
config 2 files drift ░░░░░░░░░░░░░░░░░░░░ 0 risk none
shared 1 file drift ████████████████████ 100 risk high
 
╭──────────────────────────────────────────╮
DriftScore Summary
╰──────────────────────────────────────────╯
 
DriftScore: 66/100
Risk Level: HIGH
Projects: 9
Classified: 8 nano · 1 micro · 0 small · 0 standard
Billable: 0.42 · 9 detected → 0.42 billable projects (micro-project pricing)
0.1 micro · 0.32 nano
These fractions add up across repositories, then round down to whole billable projects.
 
Score Breakdown
Runtime: ████████████████████ 100
Frameworks: █████████▏░░░░░░░░░░ 46
Dependencies: ██████▏░░░░░░░░░░░░░ 31
EOL Risk: ████████████████████ 100
 
Scanned at 2026-08-19T10:20:40.993Z · 5.9s · 286 files scanned · 56 workspace files · 27 dirs
Press Run to start.