The web is changing. Users are no longer just Googling your website—they are asking ChatGPT, Perplexity, and SearchGPT to summarize your articles and find your products.
But there is a massive problem: AI agents don't read CSS. They struggle to parse messy HTML
tags. If an AI web-browser visits your site and can't confidently figure out what your content is, it will either hallucinate the facts or ignore your site entirely.Standard OpenGraph ( og:title ) tags aren't enough anymore. You need JSON-LD (Schema.org)—the universal language that AI models are natively trained on.
Instead of manually writing JSON schemas for every page, I built an open-source Python middleware that does it completely automatically.
Here is how to make your FastAPI or Django app 100% AI-readable in 60 seconds.
Meet AutoAI-Optimize
AutoAI-Optimize is an enterprise-grade middleware that intercepts your HTML responses, classifies the page, and auto-injects perfectly formed JSON-LD data into the of your site.
Step 1: Install the library
pip install autoai-optimize
Step 2: Add the Middleware (FastAPI Example)
from fastapi import FastAPI
from autoai_optimize.frameworks.fastapi import AutoAIMiddleware
from autoai_optimize.config import Config
app = FastAPI()
# Secure your private routes from being scanned by the AI
config = Config(deny_paths=("/admin/", "/private/"))
# Add the middleware in 1 line of code
app.add_middleware(AutoAIMiddleware, config=config)
That's it. You don't have to change a single line of your actual routing or business logic.
How it Works Under the Hood
When a user (or an AI agent) hits your URL, the middleware kicks in:
- Deterministic Classification: It scans the URL and HTML to determine if the page is an Article , Product , or Profile .
- Extraction: It safely extracts the title, description, price, author, etc.
- Injection: It builds the JSON-LD script and mutates your DOM to inject it before sending the response back to the client.
The "Zero-Cost" Architecture (0ms Latency)
As backend engineers, our first question is always: "How much latency does this add to my server?"
I knew this library would be useless if it slowed down human users. To solve this, I built a thread-safe MD5 LRU in-memory cache.
Here are the actual benchmark results from running the library on an e-commerce product page:
Metric │ Time │ Description
─────────────────────────────┼─────────────────────────────┼───────────────────────────────────────────────────────────
Cold Start │ 2.36 ms │ Initial BeautifulSoup parsing, extraction, and injection.
Warm Start (Cache Hit) │ 0.0139 ms │ Returning enriched HTML from MD5 Cache.
High Throughput Avg │ 0.0028 ms │ Average time per request over 1,000 consecutive requests.
Because the cache holds the pre-computed HTML string, repeated hits to the same page average 0.0028 milliseconds. It is a literal zero-cost abstraction for your server.
100% AI Bot Coverage
This library solves for both types of AI web-crawlers:
- The Direct Visitor (ChatGPT): When a user drops a specific link into ChatGPT, the bot visits the HTML and instantly reads the inline JSON-LD script.
- The Bulk Crawler (Googlebot): The library can also generate a centralized website_schemas.json manifest. Advanced crawlers can hit the /api/ai endpoint a download your entire site's semantic structure in 50ms without ever parsing HTML.
Try it out!
If you want to ensure your Python web apps survive the AI Search revolution, check out the source code! I would love to hear your feedback on the caching implementation.
⭐️ GitHub: https://github.com/AlfaPankaj/autoai-optimize
📦 PyPI: https://pypi.org/project/autoai-optimize/
Top comments (0)