Giving an LLM unrestricted access to a production database without guardrails is a recipe for data loss, compliance violations, and costly outages.
In many teams the quickest way to let ChatGPT write SQL is to embed a static database user and password directly in the prompt or in a configuration file that the LLM can read. The model then executes queries with the same privileges as a human DBA, without any visibility into which statements succeeded or failed. Because the connection bypasses any review process, a single hallucinated DROP TABLE or an accidental SELECT that returns PII can go unnoticed until the damage is done.
Common mistakes amplify the risk. First, the credential is often hard‑coded and shared across multiple agents, creating a single point of compromise. Second, there is no query‑level audit; the database logs show only the user name, not the originating LLM or the intent behind the statement. Third, sensitive columns are never masked, so any response that includes credit‑card numbers or personal identifiers is sent straight back to the model. Fourth, there is no workflow to pause a risky operation for human approval, so destructive commands run automatically. Finally, because the LLM talks directly to Postgres, the system cannot record a replayable session for forensic analysis.
To close these gaps, the enforcement point must sit on the data path, between the AI agent and the database, where it can inspect each wire‑protocol message and apply policy before the database ever sees it. This is exactly what hoop.dev provides.
Why guardrails matter for ChatGPT on Postgres
hoop.dev acts as a Layer 7 gateway that proxies every PostgreSQL request. The gateway is deployed inside the same network segment as the database, and an agent runs locally to forward traffic through the gateway. Because the gateway sees the full protocol, it can enforce a range of guardrails without requiring any changes to the LLM or the client code.
Setup: identity and least‑privilege
Authentication is handled by an OIDC or SAML provider such as Okta or Azure AD. The LLM presents a token that hoop.dev validates, extracting group membership to decide which policies apply. The token never carries database credentials; hoop.dev holds the credential internally and presents it to Postgres only after the request has passed all checks.
The data path: where enforcement lives
All PostgreSQL traffic flows through hoop.dev, making it the sole place where policy can be applied. Because the gateway sits on the wire, it can:
- Mask sensitive fields in query results, ensuring that credit‑card numbers, SSNs, or other regulated data are redacted before they reach the LLM.
- Block dangerous commands such as DROP, ALTER, or TRUNCATE unless an explicit approval is granted.
- Route high‑risk queries, those that touch production tables or exceed a row‑count threshold, to a just‑in‑time approval workflow, where a human reviewer can allow or deny the operation.
- Record every session, including the full request and response stream, for later replay, audit, and forensic investigation.
Because hoop.dev is the only component that can see the raw SQL, these guardrails are enforced regardless of how the LLM is invoked. The model never sees the underlying credential, and the database never receives an unchecked statement.
Enforcement outcomes
hoop.dev records each session in an audit log, providing a detailed evidence trail for compliance audits. It masks sensitive columns in real time, reducing the chance of accidental data exposure. It blocks destructive commands unless they have been approved, limiting blast radius. And it enables a just‑in‑time approval step that forces a human to review high‑impact queries before they execute.
Getting started with guardrails for ChatGPT
Deploy the gateway using the quick‑start Docker Compose file, which brings up hoop.dev alongside an OIDC configuration. Register the Postgres instance as a connection, supplying the host, port, and a low‑privilege service account that only needs SELECT and INSERT on the allowed schemas. Define masking policies for columns that contain PII, and configure the approval workflow for any DDL or data‑destructive statements. Once the gateway is running, point the LLM’s database client at the hoop.dev endpoint instead of the raw Postgres host.
All of the detailed steps, creating the OIDC client, adding the Postgres connection, writing masking rules, and enabling approvals, are covered in the official documentation. Start with the getting‑started guide and explore the full feature set in the learn section.
FAQ
How does hoop.dev stop an accidental data leak? The gateway inspects the response before it reaches the LLM and applies inline masking to any column marked as sensitive. The LLM never receives the raw value.
Can I keep using my existing psql client? Yes. The client connects to the hoop.dev endpoint just like it would to a regular PostgreSQL server. No code changes are required.
What happens if the LLM tries a forbidden command? hoop.dev blocks the statement and returns an error to the client. If the command is classified as high‑risk, it is instead sent to the approval workflow for a human decision.
Explore the source code and contribute on GitHub.