DEV Community

Mads Hansen
Mads Hansen

Posted on

Before ChatGPT queries your SQL database, define the answer contract

Connecting ChatGPT to a SQL database is the easy part.

The harder question is what a trustworthy answer must contain.

Without a shared contract, one prompt returns a global total, the next inherits a tenant from chat history, and a third silently uses yesterday's definition of an active customer.

Define the answer contract first:

  • authenticated identity and structural scope
  • approved metric definition and version
  • source freshness and acceptable staleness
  • row, byte, runtime, and detail limits
  • filters, provenance, truncation, and trace reference
  • deterministic handling of ambiguity

The model should not choose its own tenant or production role. Conversation text can narrow structural scope; it should not widen it.

And “I cannot answer safely yet” is a valid outcome. Missing timezone, undefined metric, stale data, excessive result size, or insufficient authorization should map to a specific clarification, refusal, or approval step.

A fluent number is not yet a trustworthy answer. A scoped, versioned, freshness-aware, reviewable result is.

Full guide: Connect ChatGPT to a SQL database: define the answer contract first

Top comments (0)