The problem
The first version of the forecasting tool asked a large language model to do everything: read the campaign brief, pick inventory, and calculate impressions, CPMs and reach. The output read well. The numbers, however, were not always right, and there was no way to know which ones.
Our approach: keep the math deterministic
We redesigned the system around one rule: the model never computes a number.
- Deterministic engines now calculate every figure: the inventory waterfall, data-CPM tiering and strategy allocation across display, video, native, CTV, audio, social and more.
- The LLM only classifies and writes. It maps free-text briefs to categories and explains the forecast in plain language.
- Guardrails sit between the two: JSON schema validation with retries, post-processing overrides and invariant spot-checks that reject any output that doesn't add up.
Self-hosted models
The models run on the client's own hardware using llama.cpp on CUDA GPUs in Docker, behind an OpenAI-compatible API. We started with a quantized DeepSeek-R1-Distill-Qwen-32B and later moved to Qwen3.5-35B-A3B on an RTX 5090. The client layer handles JSON mode, retries with temperature adjustment and multi-endpoint failover.
From prototype to production service
We ported the Python/Flask prototype (a ~9K-line orchestrator) to a .NET 10 worker service with four dependency-injected pipelines: DSP, Performance Max, Geo-Framing and Meta. Product rules and thresholds moved into configuration (Redis and the database), and fragile text detection was replaced with ID-based lookups passed end to end.
Real data or no forecast
- Geo-resolution on the US Census Bureau API (ZIP, county, city, state, DMA and radius), with the LLM normalizing free-text locations first.
- Meta Marketing API delivery estimates, with LLM-suggested categories verified against Meta's own data.
- When real data is missing, the job fails loudly instead of guessing.
The result
Forecasts the sales team can defend: every number traceable to deterministic code, every narrative checked before it ships.