Routing, Fallbacks, and Graceful Degradation › Partial Service: Returning a Reduced but Honest Result

Michael BrenndoerferDecember 2, 20263 min read
Language AI HandbookAll chapters
Part 64 of 67Compound AI System Design
Chapter 486Routing, Fallbacks, and Graceful Degradation › Partial Service: Returning a Reduced but Honest Result
Reading section 6 of 10 · Partial Service: Returning a Reduced but Honest Result · 3 minSection 6 of 10 · 3 min

Section 6 of 10 · 3 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

If the attempt budget is exhausted or no tier passes, an allowed public policy excerpt yields a partial answer. This path says what is missing. Otherwise the router abstains. Withheld synthesis and missing evidence are different states. A private request cannot use the public excerpt path unless the caller has already determined that the excerpt is appropriate to return.

PythonIn [19]
CollapseExpand
from enum import Enum


class Outcome(Enum):
    COMPLETE = "complete"
    PARTIAL = "partial"
    ABSTAIN = "abstain"


@dataclass(frozen=True)
class Option:
    tier: str
    eligible: bool
    available: bool
    candidate: tuple[str, float] | None


@dataclass(frozen=True)
class ServiceResult:
    outcome: Outcome
    text: str
    tier: str | None
    attempted: tuple[str, ...]


def serve(
    options: tuple[Option, ...],
    *,
    safe_excerpt: str | None,
    max_attempts: int,
    threshold: float = 0.65,
) -> ServiceResult:
    attempts = []
    for option in options:
        if len(attempts) >= max_attempts:
            break
        if not option.eligible or not option.available:
            continue
        attempts.append(option.tier)
        if option.candidate is None:
            continue
        text, score = option.candidate
        if score >= threshold:
            return ServiceResult(
                Outcome.COMPLETE, text, option.tier, tuple(attempts)
            )
    if safe_excerpt:
        return ServiceResult(
            Outcome.PARTIAL,
            "Public policy excerpt only. Summary unavailable.\n" + safe_excerpt,
            None,
            tuple(attempts),
        )
    return ServiceResult(
        Outcome.ABSTAIN, "I couldn't verify an answer.", None, tuple(attempts)
    )
PythonIn [20]
CollapseExpand
primary = Option("Primary", True, False, None)
backup = Option(
    "Backup", True, True, ("Fictional returns period: 30 days.", 0.82)
)
unapproved = Option("Unapproved", False, True, ("Unverified answer", 0.99))
timeout = Option("Transient failure", True, True, None)
excerpt = "The demo store accepts unopened returns within 30 days."

complete = serve(
    (unapproved, primary, backup), safe_excerpt=None, max_attempts=2
)
partial = serve((timeout, backup), safe_excerpt=excerpt, max_attempts=1)
abstain = serve((unapproved, primary), safe_excerpt=None, max_attempts=2)

assert complete.outcome is Outcome.COMPLETE and complete.attempted == (
    "Backup",
)
assert partial.outcome is Outcome.PARTIAL and partial.attempted == (
    "Transient failure",
)
assert abstain.outcome is Outcome.ABSTAIN and abstain.attempted == ()
assert serve((backup,), safe_excerpt=None, max_attempts=0).attempted == ()
borderline = Option("Exact threshold", True, True, ("Fixture answer", 0.65))
assert (
    serve((borderline,), safe_excerpt=None, max_attempts=1).outcome
    is Outcome.COMPLETE
)
no_answers = measure(rows, (0, 1, 2), 1.1)
assert no_answers.answered_accuracy is None
assert "answered accuracy=undefined" in format_benchmark(
    "Always abstain", no_answers
)
for result in (complete, partial, abstain):
    print(
        f"{result.outcome.value} | tier={result.tier} | attempts={result.attempted}"
    )
ConsoleOut [20]
CollapseExpand
complete | tier=Backup | attempts=('Backup',)
partial | tier=None | attempts=('Transient failure',)
abstain | tier=None | attempts=()

These fixtures prove the route and outcome for their scripted conditions. They do not estimate real availability. If F1F_1 and F2F_2 are the failure events for two attempts, joint failure is P(F1)P(F2∣F1)P(F_1)P(F_2\mid F_1) when P(F1)>0P(F_1)>0. If P(F1)=0P(F_1)=0, joint failure is zero. It equals the product of marginal failure rates under independence. A shared network, region, or upstream dependency can make failure on the backup more likely given failure on the primary.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy