That GPT-4o hallucination that invented a whole `asyncpg` API OpenAI's GPT-4o hallucinated a non-existent asyncpg API, inventing parameters like health_check_interval and health_check_query for create_pool() and a Pool.health_check() method, which caused TypeError and AttributeError in Python code. The model conflated real asyncpg features—max_inactive_connection_lifetime, acquire() timeout, and manual SELECT 1 checks—into a plausible but fictional interface, as documented in a developer's blog post. The incident highlights the risk of AI-generated code that appears coherent but is factually incorrect, requiring developers to verify against official documentation and source code. That GPT-4o hallucination that invented a whole asyncpg API The prompt Asked GPT-4o for a production-ready asyncpg pool pattern with proper lifecycle management and health checks What it gave me python import asyncpg from contextlib import asynccontextmanager class DatabasePool: def init self, dsn: str, min size: int = 10, max size: int = 50 : self.dsn = dsn self.min size = min size self.max size = max size self. pool: asyncpg.Pool | None = None self. health check task: asyncio.Task | None = None async def initialize self - None: self. pool = await asyncpg.create pool self.dsn, min size=self.min size, max size=self.max size, command timeout=60, These two parameters DO NOT EXIST in asyncpg 0.29.0 health check interval=30, health check query="SELECT 1", self. health check task = asyncio.create task self. health monitor @asynccontextmanager async def acquire self - AsyncGenerator asyncpg.Connection, None : if self. pool is None: raise RuntimeError "Pool not initialized" async with self. pool.acquire as conn: yield conn async def health monitor self - None: while True: await asyncio.sleep 30 This method DOES NOT EXIST await self. pool.health check async def close self - None: if self. health check task: self. health check task.cancel if self. pool: await self. pool.close The error that sent me down the rabbit hole TypeError: create pool got unexpected keyword arguments: 'health check interval', 'health check query' AttributeError: 'Pool' object has no attribute 'health check' What I tried before realizing it was hallucinated 1. Checked asyncpg docs — no health check interval , no health check query , no Pool.health check 2. Searched GitHub issues — zero results for these parameters 3. Dug through source — create pool signature only accepts: dsn , min size , max size , command timeout , timeout , loop , connection class , init , setup , server settings , statement cache size , max queries , max inactive connection lifetime 4. Tested on 0.28.0, 0.29.0, 0.30.0 — same error every version Where the hallucination likely came from The model conflated three real things: | Real thing | What it does | |------------|--------------| | max inactive connection lifetime asyncpg 0.29+ | Closes idle connections after N seconds | | asyncpg.Pool.acquire timeout parameter | Fails fast if no connection available | | asyncpg.Connection.execute "SELECT 1" | Manual health check pattern people actually use | It then invented a cohesive API around these concepts that looks like it should exist — consistent naming, sensible defaults, proper async context manager usage. That's the dangerous part: it's not random garbage, it's plausible garbage. The actual working pattern python import asyncpg import asyncio from contextlib import asynccontextmanager class DatabasePool: def init self, dsn: str, min size: int = 10, max size: int = 50 : self.dsn = dsn self.min size = min size self.max size = max size self. pool: asyncpg.Pool | None = None async def initialize self - None: self. pool = await asyncpg.create pool self.dsn, min size=self.min size, max size=self.max size, command timeout=60, max inactive connection lifetime=300, Real parameter @asynccontextmanager async def acquire self - AsyncGenerator asyncpg.Connection, None : if self. pool is None: raise RuntimeError "Pool not initialized" async with self. pool.acquire timeout=10 as conn: Real timeout yield conn async def health check self - bool: """Manual health check — call this from your /health endpoint""" if self. pool is None: return False try: async with self. pool.acquire timeout=2 as conn: await conn.execute "SELECT 1" return True except Exception: return False async def close self - None: if self. pool: await self. pool.close The pattern I'm seeing Hallucinations cluster around plausible API extensions — methods/parameters that should exist based on naming conventions and common patterns. The model isn't retrieving; it's synthesizing a consistent interface from partial knowledge. Anyone else hit this with asyncpg or other libraries? Wondering if there's a systematic way to catch these before they waste hours. Next Greg Brockman's tightening grip on OpenAI has me nervous about → /en/threads/7191/ a library of Claude prompt techniques https://tanyan888.com/ , with plenty of directly applicable cases.