Prompt Details
Model
(claude-4-6-sonnet)
Token size
5,734
Example input
[AI_GENERATED_SQL]: SELECT u.id, u.email, o.total_amount FROM users u JOIN orders o ON u.id = o.user_id WHERE o.created_at > '2024-01-01'
[ORIGINAL_PROMPT]: Get users and their orders placed after 2024
[KNOWN_SCHEMA]: CREATE TABLE users ( id INT, email VARCHAR(255) ); CREATE TABLE orders ( id INT, user_id INT, total_amount DECIMAL(10,2), created_at DATETIME );
[CONSTRAINT_CATALOG]: ALTER TABLE orders ADD CONSTRAINT FK_orders_users FOREIGN KEY (user_id) REFERENCES users(id);
Example output
{EXECUTIVE_SUMMARY}
- Identifiers checked: 6
├─ Catalog-verified: 2 | Schema-verified: 4
└─ Unverified: 0 | Suspicious: 0
- Implicit assumptions: 4 | Inferred rules: 1
- Catalog-enforced rules: 1 (strongest correctness signal)
- Validation queries: 3
- VERDICT: PROCEED_WITH_VALIDATION
- Top risk: JOIN may silently drop users with no orders (INNER vs LEFT ambiguity); date filter boundary excludes orders on exactly 2024-01-01.
---
{IDENTIFIER_AUDIT}
- Identifier: users.id
Tier: {CATALOG_VERIFIED}
Source: FK_orders_users — referenced as the parent key in the foreign key constraint; implicitly confirms existence and uniqueness as the referenced column.
Risk-if-wrong: N/A — catalog-confirmed.
Likelihood: LOW
- Identifier: users.email
Tier: {SCHEMA_VERIFIED}
Source: CREATE TABLE users — declared as VARCHAR(255).
Risk-if-wrong: Column exists per schema but has no catalog-enforced constraint; no NOT NULL or UNIQUE enforcement confirmed. NULLs or duplicates are possible.
Likelihood: LOW
- Identifier: orders.id
Tier: {SCHEMA_VERIFIED}
Source: CREATE TABLE orders — declared as INT. Not referenced in the constraint catalog (no PK constraint surfaced).
Risk-if-wrong: No catalog evidence of a primary key on orders.id; uniqueness not engine-enforced per available catalog.
Likelihood: LOW
- Identifier: orders.user_id
Tier: {CATALOG_VERIFIED}
Source: FK_orders_users — explicitly named as the foreign key column referencing users(id). Engine enforces referential integrity.
Risk-if-wrong: N/A — catalog-confirmed. Every orders.user_id value is guaranteed to exist in users.id.
Likelihood: LOW
- Identifier: orders.total_amount
Tier: {SCHEMA_VERIFIED}
Source: CREATE TABLE orders — declared as DECIMAL(10,2).
Risk-if-wrong: No CHECK constraint confirming non-negativity or non-NULL. Could contain NULLs or negative values if application layer does not enforce.
Likelihood: MEDIUM
- Identifier: orders.created_at
Tier: {SCHEMA_VERIFIED}
Source: CREATE TABLE orders — declared as DATETIME. No DEFAULT constraint present in catalog.
Risk-if-wrong: No catalog-enforced DEFAULT or NOT NULL. NULLs in created_at would silently be excluded by the WHERE filter without error.
Likelihood: MEDIUM
---
{IMPLICIT_ASSUMPTIONS}
- Type: Join
Assumption: INNER JOIN is intended — only users who have at least one matching order row are returned. Users with no orders are silently dropped.
CatalogCrossCheck: NOT_AVAILABLE — the FK confirms orders.user_id → users.id referential integrity, but does not mandate every user has an order. The cardinality is one-to-many; zero orders per user is permitted.
Likely_Wrong_If: The prompt intent is "get all users and show their orders if any" (LEFT JOIN semantics). The word "and" in "users and their orders" is ambiguous.
Severity: HIGH
- Type: NULL
Assumption: orders.created_at is never NULL, so the WHERE filter `o.created_at > '2024-01-01'` behaves deterministically for every row.
CatalogCrossCheck: CONTRADICTED — no NOT NULL constraint appears in the catalog for orders.created_at. NULLs will silently fail the comparison and be excluded without warning.
Likely_Wrong_If: Any order row was inserted without a created_at value.
Severity: HIGH
- Type: NULL
Assumption: orders.total_amount is never NULL and is meaningful for all returned rows.
CatalogCrossCheck: CONTRADICTED — no NOT NULL or CHECK constraint confirmed in catalog. NULLs will propagate silently into the result set.
Likely_Wrong_If: Orders exist with no recorded total (e.g. draft or cancelled orders stored in the same table).
Severity: MEDIUM
- Type: BusinessRule
Assumption: The date boundary `> '2024-01-01'` is exclusive — orders placed exactly on 2024-01-01 00:00:00 are excluded. The prompt says "after 2024" which could mean after the year 2024 (i.e. >= 2025-01-01) or after the start of 2024 (i.e. >= 2024-01-01).
CatalogCrossCheck: NOT_AVAILABLE — no CHECK constraint on created_at to clarify intent.
Likely_Wrong_If: The user meant "during or after 2024" (>= '2024-01-01') or "placed in 2025 onward" (>= '2025-01-01').
Severity: MEDIUM
---
{EXTRACTED_BUSINESS_RULES}
- Rule: Only orders with a created_at timestamp strictly after January 1, 2024 are included.
Source: {INFERRED_BY_AI} — the prompt says "after 2024," which is ambiguous. The AI resolved this as `> '2024-01-01'`, but "after 2024" most naturally reads as after the entire year 2024, i.e. `>= '2025-01-01'`. This interpretation is not stated explicitly in the prompt and is not catalog-enforced.
Risk-if-fabricated: The result set may span all of 2024 when the user expected only 2025-onward data, or vice versa — a silent business logic error returning the wrong population entirely.
- Rule: Each result row pairs one user with one order (one-to-many join; users with multiple orders appear multiple times).
Source: {CATALOG_ENFORCED} — FK_orders_users enforces that orders.user_id references users.id, confirming the one-to-many relationship. Multiple order rows per user are structurally expected and the JOIN correctly reflects this.
Risk-if-fabricated: N/A — catalog-confirmed relationship.
---
{VALIDATION_QUERIES}
- Purpose: Confirm that orders.created_at contains NULLs, quantifying the silent-exclusion risk from the WHERE filter.
SQL:
SELECT COUNT(*) AS null_created_at_count
FROM orders
WHERE created_at IS NULL;
SafeIfReturns: 0 — no NULLs; filter is safe. Any value > 0 means rows are silently dropped.
- Purpose: Confirm that orders.total_amount contains NULLs, quantifying silent NULL propagation into the result set.
SQL:
SELECT COUNT(*) AS null_total_amount_count
FROM orders
WHERE total_amount IS NULL;
SafeIfReturns: 0 — no NULLs in result. Any value > 0 indicates potential data quality issue in the output.
- Purpose: Verify the date boundary interpretation — check how many orders fall exactly on 2024-01-01 and how many fall in the full year 2024 vs. 2025 onward, to surface the "after 2024" ambiguity.
SQL:
SELECT
SUM(CASE WHEN created_at = '2024-01-01' THEN 1 ELSE 0 END) AS on_boundary,
SUM(CASE WHEN created_at >= '2024-01-01' AND created_at < '2025-01-01' THEN 1 ELSE 0 END) AS in_2024,
SUM(CASE WHEN created_at >= '2025-01-01' THEN 1 ELSE 0 END) AS after_2024
FROM orders;
SafeIfReturns: Inspect the ratio. If after_2024 is the intended population, the SQL's `> '2024-01-01'` is wrong — it includes all of 2024.
---
{VERDICT_MATRIX}
- Identifier risk: LOW
Reasoning: 2 of 6 identifiers are {CATALOG_VERIFIED} (users.id, orders.user_id); remaining 4 are {SCHEMA_VERIFIED} from provided CREATE TABLE statements. No {UNVERIFIED} or {SUSPICIOUS_AI_PATTERN} identifiers present. Per composition rules: majority {CATALOG_VERIFIED} + {SCHEMA_VERIFIED} mix → LOW.
- Logic risk: MEDIUM
Reasoning: 1 rule is {CATALOG_ENFORCED} (join cardinality), which is a strong correctness signal. However, 1 rule is {INFERRED_BY_AI} with a meaningful mis-interpretation risk (date boundary). Additionally, 2 implicit assumptions are catalog-CONTRADICTED (NULLs in created_at and total_amount not ruled out). This combination of one fabricated rule and two contradicted assumptions elevates logic risk above LOW.
- Composite: PROCEED_WITH_VALIDATION
Reasoning: Identifier risk is LOW (catalog + schema coverage is complete; no hallucinated identifiers). Logic risk is MEDIUM (one AI-inferred rule with plausible mis-interpretation; two NULL risks contradicted by catalog absence of NOT NULL constraints). Applying composition rules: LOW identifier + MEDIUM logic = PROCEED_WITH_VALIDATION. The SQL will not fail due to bad identifiers, but it may silently return the wrong population due to the date interpretation ambiguity and NULL edge cases. Do not run in production until validation queries are reviewed and the "after 2024" intent is confirmed with the requester.
---
{NEXT_ACTIONS}
- Run validation queries in this order:
1. NULL check on created_at (highest severity — directly affects WHERE filter correctness).
2. Date boundary distribution query (surfaces the "after 2024" ambiguity before any data is acted on).
3. NULL check on total_amount (medium severity — affects output quality, not row selection).
- Highest-leverage check: Clarify with the requester whether "after 2024" means `> '2024-01-01'` (all of 2024 and beyond), `>= '2024-01-01'` (same with boundary included), or `>= '2025-01-01'` (strictly after the year 2024). This single ambiguity is the highest-risk logic error in the query and cannot be resolved by any validation query — it requires human confirmation.
- Join intent clarification required: Confirm whether INNER JOIN (current) is correct or whether a LEFT JOIN is needed to retain users with no qualifying orders. The FK catalog confirms the relationship exists but does not determine which users should appear in output.
- If catalog absent: The audit operated with a partial catalog (FK only; no CHECK, DEFAULT, NOT NULL, or PK constraints for most columns). Pulling the full catalog — particularly NOT NULL and DEFAULT constraints for orders.created_at and orders.total_amount — would allow a re-audit and may reduce logic risk rating if those columns are confirmed non-nullable.
By purchasing this prompt, you agree to our terms of service
CLAUDE-4-6-SONNET
This prompt acts as an adversarial SQL auditor that:
Detects hallucinated tables/columns
Flags “too-perfect” AI naming patterns
Cross-checks against your real schema + constraint catalog
Surfaces hidden assumptions (joins, NULLs, business rules)
Generates safe validation queries before execution
Outputs a clear verdict: PROCEED / VALIDATE / DO NOT RUN
...more
Added 1 week ago
