CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl-labs/postgresql-python-best-practices

PostgreSQL patterns for Python with psycopg and asyncpg — connection pooling,

99

1.15x
Quality

99%

Does it follow best practices?

Impact

99%

1.15x

Average score across 5 eval scenarios

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

criteria.jsonevals/scenario-4/

{
  "context": "Tests whether the agent correctly uses both psycopg_pool and asyncpg pools in the same application, uses correct placeholder syntax for each driver (%s vs $1), uses context managers for both sync and async connections, applies server-side cursors for the large export, uses transactions and bulk updates for order sync, and manages lifecycle of both pools. The task describes business reports without naming these patterns.",
  "type": "weighted_checklist",
  "checklist": [
    {
      "name": "psycopg_pool for sync reports",
      "description": "Sync report functions use psycopg_pool.ConnectionPool (not individual connections) with min_size and max_size",
      "max_score": 10
    },
    {
      "name": "asyncpg pool for async API",
      "description": "Async API functions use asyncpg.create_pool() with min_size and max_size, created in startup handler",
      "max_score": 10
    },
    {
      "name": "Correct placeholder per driver",
      "description": "psycopg queries use %s placeholders and asyncpg queries use $1/$2 placeholders -- the two syntaxes are never mixed within a single driver",
      "max_score": 14
    },
    {
      "name": "Context managers for sync connections",
      "description": "Sync report functions use 'with pool.connection() as conn:' or equivalent context manager",
      "max_score": 10
    },
    {
      "name": "Async context managers for async connections",
      "description": "Async API functions use 'async with pool.acquire() as conn:' context manager",
      "max_score": 10
    },
    {
      "name": "Server-side cursor for cohort export",
      "description": "Customer cohort export uses a named server-side cursor with fetchmany batching or streaming -- not fetchall() for 2M customers",
      "max_score": 12
    },
    {
      "name": "Transaction for batch order sync",
      "description": "Daily order sync wraps all status updates in a transaction (async with conn.transaction()) for atomicity",
      "max_score": 10
    },
    {
      "name": "Bulk update for order sync",
      "description": "Order status updates use executemany or equivalent batch pattern -- not individual UPDATE statements in a loop",
      "max_score": 8
    },
    {
      "name": "Both pools cleaned up on shutdown",
      "description": "Both the psycopg and asyncpg pools are closed on application shutdown",
      "max_score": 8
    },
    {
      "name": "DATABASE_URL from environment",
      "description": "Connection strings come from environment variables, not hardcoded",
      "max_score": 6
    },
    {
      "name": "Dict row factory for psycopg reports",
      "description": "psycopg report queries use dict_row factory for readable results",
      "max_score": 6
    },
    {
      "name": "No SQL injection vectors",
      "description": "No f-strings or string concatenation used for building SQL with dynamic values anywhere",
      "max_score": 6
    }
  ]
}

evals

tile.json