LLMS Central - The Robots.txt for AI
Industry News

Bob Belderbos: Protocol or ABC for a pluggable interface?

Belderbos.dev2 min read
Share:
Bob Belderbos: Protocol or ABC for a pluggable interface?

Original Article Summary

When you need a common interface for swappable backends, the reflex is to use a good ol' abstract base class (ABC). But typing.Protocol offers a more flexible alternative.

Read full article at Belderbos.dev

Our Analysis

Bob Belderbos's comparison of `typing.Protocol` versus abstract base classes (ABCs) highlights that Protocols provide a more flexible, duck‑typed way to define pluggable interfaces for swappable backends, eliminating the need for explicit inheritance while still supporting static type checking. For website owners who embed AI services—such as content moderation, recommendation engines, or chatbot widgets—this shift means you can integrate third‑party AI providers without locking your codebase into a rigid class hierarchy. Using Protocols lets you swap out providers (e.g., OpenAI, Anthropic, or Cohere) by simply matching the expected method signatures, reducing deployment friction and keeping your site’s AI pipeline agile. However, the looser coupling also makes it easier for unvetted bots to masquerade as legitimate services, so precise interface contracts become critical for security and compliance. **Actionable tips:** 1. Define a `typing.Protocol` for every external AI endpoint (e.g., `class TextGenerator(Protocol): def generate(self, prompt: str) -> str`). Then enforce these contracts in your llms.txt file by listing the allowed provider domains, ensuring only compliant services can interact with your site. 2. Use automated type‑checking tools (mypy, pyright) in your CI pipeline to verify that any new AI integration adheres to the Protocol, catching mismatched signatures before they reach production. 3. Deploy a lightweight request‑signature validator that checks incoming API calls against the Protocol’s method signatures, flagging anomalous traffic that could indicate rogue bots attempting to exploit your pluggable interface.

Track AI Bots on Your Website

See which AI crawlers like ChatGPT, Claude, and Gemini are visiting your site. Get real-time analytics and actionable insights.

Start Tracking Free →