Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Format: [Keep a Changelog](https://keepachangelog.com/) · [SemVer](https://semv

## [Unreleased]

### Changed
- `geo citations` and `POST /api/citations`: when the provider returns no sources (every provider except Perplexity) and the brand is not mentioned either, the verdict is the new `not_measurable` instead of `invisible`. Without sources the check cannot tell "not cited" from "sources not available". Existing verdicts keep their names and meaning (the CLI text of `mentioned_only` no longer says "never cites" when the provider returns no sources); clients that switch on `verdict` should handle the new value.

### Fixed
- `G-DATES` no longer counts a date that appears only inside an HTML comment (for example `<!-- Published 2026-03-12 -->`) as a visible date. The 4.31.1 text-date check read comments by mistake; a page whose only date is in a comment goes back to the "Date only in structured data" warning. Pages that show the date as real text, a `<time datetime>` element or an `article:published_time` meta tag are unchanged.

Expand Down
25 changes: 23 additions & 2 deletions src/geo_optimizer/cli/citations_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,36 @@
"cited": "✅ CITED — {domain} appears among AI answer sources, but not consistently.",
"mentioned_only": "🟡 MENTIONED ONLY — AI knows the brand but never cites {domain} as a source.",
"invisible": "❌ INVISIBLE — AI answers neither mention {brand} nor cite {domain}.",
# mentioned_only from a provider that returns no sources: "never cites" would claim more than was observed.
"mentioned_only_unobserved": (
"🟡 MENTIONED ONLY — AI answers name {brand}. This provider returns no sources, "
"so citations of {domain} cannot be checked."
),
"not_measurable": "⚪ NOT MEASURABLE — this provider returns no sources, so citations of {domain} cannot be checked.",
}

_VERDICT_ADVICE = {
"strong": "Keep your content fresh and monitor for regressions.",
"cited": "Strengthen citability: statistics, quotable passages, llms.txt depth (run: geo audit).",
"mentioned_only": "AI learned about you from third parties. Make your own pages the citable source (run: geo audit).",
"invisible": "Start with the basics: geo audit --url https://{domain} and fix the HIGH recommendations first.",
"mentioned_only_unobserved": "Re-run with Perplexity (PERPLEXITY_API_KEY) to see which sources the answers cite.",
"not_measurable": "Re-run with Perplexity (PERPLEXITY_API_KEY) to see which sources the answers cite.",
}


# Providers whose answers come with the sources they used (or a SERP that lists them).
_SOURCE_OBSERVING_PLATFORMS = frozenset({"perplexity", "serpbase"})


def _verdict_key(result) -> str:
"""The text key for the verdict: a mention seen through a provider without sources gets its own wording."""
if result.verdict != "mentioned_only":
return str(result.verdict)
platform = next((e.platform for e in result.entries if e.platform), "")
return "mentioned_only" if platform in _SOURCE_OBSERVING_PLATFORMS else "mentioned_only_unobserved"


def _format_text(result) -> str:
lines: list[str] = []
lines.append("")
Expand Down Expand Up @@ -87,8 +107,9 @@ def _format_text(result) -> str:
competitors = ", ".join(f"{d} ({n})" for d, n in result.top_cited_domains)
lines.append(f"Cited instead of you: {competitors}")
lines.append("")
lines.append(_VERDICT_LINES[result.verdict].format(brand=result.brand, domain=result.domain))
lines.append(f"→ {_VERDICT_ADVICE[result.verdict].format(domain=result.domain)}")
key = _verdict_key(result)
lines.append(_VERDICT_LINES[key].format(brand=result.brand, domain=result.domain))
lines.append(f"→ {_VERDICT_ADVICE[key].format(domain=result.domain)}")
lines.append("")
if multi:
lines.append("AI answers are non-deterministic. Track citations over time with alerts → https://geoready.dev")
Expand Down
12 changes: 8 additions & 4 deletions src/geo_optimizer/core/citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ def _domains_in_text(text: str) -> list[str]:
return found


def _verdict(domain_citation_rate: float, brand_mention_rate: float) -> str:
def _verdict(domain_citation_rate: float, brand_mention_rate: float, sources_observable: bool = True) -> str:
if domain_citation_rate >= _STRONG_CITATION_RATE:
return "strong"
if domain_citation_rate > 0:
return "cited"
if brand_mention_rate > 0:
return "mentioned_only"
return "invisible"
# A provider that returns no sources cannot show that the domain is not cited: with no mention either, the
# honest answer is "not measurable with this provider", not "invisible".
return "invisible" if sources_observable else "not_measurable"


def _wilson_interval(successes: int, n: int, z: float = _CI_Z) -> tuple[float, float]:
Expand Down Expand Up @@ -269,7 +271,9 @@ def run_citation_check(
mention_ci = _wilson_interval(mentioned_count, total_answers)
# The verdict is trustworthy only if the confidence interval does not straddle
# a verdict boundary (a one-run check is treated as inherently unstable).
stable = runs > 1 and _verdict(citation_ci[0], mention_ci[0]) == _verdict(citation_ci[1], mention_ci[1])
stable = runs > 1 and _verdict(citation_ci[0], mention_ci[0], sources_observable) == _verdict(
citation_ci[1], mention_ci[1], sources_observable
)

return CitationCheckResult(
checked=True,
Expand All @@ -289,7 +293,7 @@ def run_citation_check(
domain_citation_rate_ci=citation_ci,
stable=stable,
top_cited_domains=other_domains.most_common(5),
verdict=_verdict(citation_rate, mention_rate),
verdict=_verdict(citation_rate, mention_rate, sources_observable),
)


Expand Down
2 changes: 1 addition & 1 deletion src/geo_optimizer/models/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ class CitationCheckResult:
domain_citation_rate_ci: tuple[float, float] = (0.0, 0.0) # 95% Wilson interval
stable: bool = False # True when the CI does not straddle a verdict boundary (needs runs > 1)
top_cited_domains: list[tuple[str, int]] = field(default_factory=list) # (domain, count), own domain excluded
verdict: str = "" # strong | cited | mentioned_only | invisible
verdict: str = "" # strong | cited | mentioned_only | invisible | not_measurable
surface: str = "api" # answers come from a provider API, which can differ from the chat interface people use


Expand Down
44 changes: 44 additions & 0 deletions tests/test_citations.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,3 +784,47 @@ def test_non_perplexity_provider_is_not_supported_and_has_no_numbers(self):
assert result.no_citation_answer_rate is None
# the mention and citation metrics are unaffected
assert result.brand_mention_rate == 1.0

def test_no_mention_and_no_sources_is_not_measurable_not_invisible(self):
with patch.object(citations_mod, "query_llm") as mock_q:
mock_q.return_value = LLMResponse(text="Try CompetitorX.", model="gpt-4o-mini", provider="openai")
result = run_citation_check("Acme", "acme.com", queries=["q"], provider="openai", api_key="sk-test")

assert result.brand_mention_rate == 0.0
assert result.domain_citation_rate == 0.0
assert result.verdict == "not_measurable"

def test_mention_without_sources_keeps_its_existing_verdict(self):
with patch.object(citations_mod, "query_llm") as mock_q:
mock_q.return_value = LLMResponse(text="Acme is a CRM.", model="gpt-4o-mini", provider="openai")
result = run_citation_check("Acme", "acme.com", queries=["q"], provider="openai", api_key="sk-test")

assert result.verdict == "mentioned_only"

def test_perplexity_with_no_mention_is_still_invisible(self):
with patch.object(citations_mod, "query_llm") as mock_q:
mock_q.return_value = _sonar_response("Try CompetitorX.", citations=["https://competitorx.com"])
result = run_citation_check("Acme", "acme.com", queries=["q"], provider="perplexity", api_key="pk-test")

assert result.verdict == "invisible"

def test_the_cli_prints_the_not_measurable_verdict(self):
from geo_optimizer.cli.citations_cmd import _VERDICT_ADVICE, _VERDICT_LINES

assert "not_measurable" in _VERDICT_LINES and "not_measurable" in _VERDICT_ADVICE
line = _VERDICT_LINES["not_measurable"].format(brand="Acme", domain="acme.com")
assert "acme.com" in line and "INVISIBLE" not in line

def test_cli_mentioned_only_without_sources_does_not_say_never_cites(self):
from geo_optimizer.cli.citations_cmd import _format_text

with patch.object(citations_mod, "query_llm") as mock_q:
mock_q.return_value = LLMResponse(text="Acme is a CRM.", model="gpt-4o-mini", provider="openai")
blind = run_citation_check("Acme", "acme.com", queries=["q"], provider="openai", api_key="sk-test")
with patch.object(citations_mod, "query_llm") as mock_q:
mock_q.return_value = _sonar_response("Acme is one option.", citations=["https://review-site.com/x"])
seen = run_citation_check("Acme", "acme.com", queries=["q"], provider="perplexity", api_key="pk-test")

assert "never cites" not in _format_text(blind)
assert "cannot be checked" in _format_text(blind)
assert "never cites" in _format_text(seen)