Topics
Recent articles

Software Architecture

Align AI Retry Prompts with Topic Validation

Prevent publishing failures by applying topic filters before ranking internal link candidates in AI retry prompts to ensure consistency with final validation.

Table of Contents1 sections
Vivid close-up of code on a computer screen showcasing programming details.
Vivid close-up of code on a computer screen showcasing programming details.

Publishing workflows often fail when an AI generator suggests internal links that a final validator subsequently rejects. This mismatch occurs because the generator ranks all available candidates by relevance before applying topic constraints, causing high-scoring but irrelevant links to displace valid, lower-scoring options.

Quick solution:

def get_valid_candidates(candidates, topic_filter):
    # Fixture: 2 high-score wrong-topic, 1 lower-score correct-topic
    # Failure mode: Sorting before filtering selects wrong-topic links
    eligible = [c for c in candidates if c.topic == topic_filter]
    return sorted(eligible, key=lambda x: x.score, reverse=True)[:2]

# candidates = [{"score": 10, "topic": "marketing"}, {"score": 9, "topic": "marketing"}, {"score": 5, "topic": "api"}]
# get_valid_candidates(candidates, "api") -> returns [{"score": 5, "topic": "api"}]

The Candidate Selection Failure

When a generator selects links for a retry prompt, it often treats the entire catalog as a flat pool. If your draft discusses “API Security” but the generator ranks two “General Marketing” links higher than a relevant “API Authentication” link, the validator will reject the draft. This happens even if the “API Authentication” link is perfectly eligible. To ensure your links remain useful, you must verify that the link purpose is clear from the anchor text and its surrounding context, as outlined by the W3C Link Purpose in Context guidelines.

Implementing Pre-Ranking Filters

To fix this, you must filter the candidate pool by topic before performing any ranking operations. This ensures that the generator only considers links that meet your publication’s topical requirements. If the filtered set is empty, the system should return an empty list rather than falling back to incompatible links. This approach is essential for maintaining high-quality internal linking, which helps search engines understand the relationship between pages, as described in the Google Search Central link best practices. When building these pipelines, you should also consider how to Fix Content Hash Mismatch in Publishing Pipelines to ensure your link selection logic remains consistent across different stages of the pipeline.

Verification Checklist

Continue Exploring

You Might Also Like

View all articles