Most SEO case studies are written like highlight reels: before, after, triumphant graph.
Entity coverage audits are where most content briefs quietly fall apart. You can nail search volume, intent, and heading structure, but if the draft doesn’t map to the same entities and relationships as the pages already ranking, the retrieval layer sees a thin document. Manual audits don’t scale past a handful of URLs. The fix is a Python pipeline that extracts entities, grounds them to canonical IDs, scores salience, and uses a local LLM only for the last mile: turning gaps into natural sentences. Deterministic first, generative second.
Start with ingestion. Pull the top N SERP results for a query cluster using requests and a rotating proxy if needed, then parse with trafilatura instead of raw BeautifulSoup. You want main-content extraction, not nav soup. Normalize whitespace, strip boilerplate, and keep a SHA-256 hash for cache invalidation. Run entity extraction with spaCy’s transformer NER plus a sentence-transformer model for mention embeddings. Ground each candidate to Wikidata via the API or a local QID dump; resolve aliases with rapidfuzz. Store entity QIDs, surface forms, mention spans, and embeddings in SQLite or a vector store. Cache aggressively. Embeddings are expensive; recomputing them because your cron job is not idempotent is amateur hour.
For the draft, run the same extraction and grounding path. Compute coverage as a set difference over QIDs, but don’t stop at missing entities. Weight by salience: mention frequency, position in the document, proximity to the primary entity, and relation density in the competitor entity graph. Use cosine similarity between draft and competitor entity embeddings to catch semantic neighborhoods the draft misses even when the exact surface form appears. The output should be JSON, not a spreadsheet: missing entity QID, canonical label, salience score, competitor evidence snippets, and a confidence score. That JSON becomes the contract between the audit script and the content engine.
The local LLM’s job is narrow. Do not ask it to “write better content” or “add missing entities” in one vague prompt. Feed it the grounded entity list, the draft, and the evidence snippets, then require a strict JSON schema via pydantic. The model proposes sentences that integrate specific QIDs into existing paragraphs. Validate every returned entity against the QID whitelist and the draft context. Reject hallucinated IDs. Run a readability pass and a factual consistency check against the evidence snippets. This is the difference between an AI content engine and a random text generator with a YAML file. Use llama-cpp-python or Ollama for a quantized 7B/8B model; reserve larger models for adjudication only. Chunk long drafts, map-reduce suggestions, and log prompts plus responses for audit trails.
Orchestration matters more than model choice. Wrap the pipeline in a CLI with typer and a config YAML so query clusters, SERP depth, model paths, and thresholds are versioned. Make each stage idempotent, with retry logic and exponential backoff on API calls. Run on cron for recrawl checks or Airflow if you need DAG-level observability. Persist run artifacts: SERP hashes, entity JSON, prompt logs, and final suggestions. Diff runs to see which entities appeared after publication. Treat entity coverage like a CI check: fail the content brief if salience for primary and secondary entities falls below threshold.
For startup marketers, the leverage is obvious. A writer gets a ranked list of missing entities with evidence and proposed sentences, not a generic “add more depth” note. Editors review before publish; no auto-push. The script handles the boring extraction and comparison; the LLM handles phrasing; the grounding layer handles truth. That’s the sane division of labor. Build it once, version it, and your content engine stops guessing what topical authority means and starts measuring it.



