🎯 SQL Practice

Advanced Prompting

The techniques that separate basic Claude usage from expert-level results.

Why prompting matters more than people think

Claude's output quality varies dramatically based on how you prompt it. The same question phrased differently can produce a generic answer or a precisely tailored, expert-level response. Understanding what Claude responds to β€” and why β€” is the core skill this lesson builds.

The RRCF framework

For any complex prompt, think through four components:

EXAMPLE: WEAK vs STRONG PROMPT

Weak: "Review my SQL query."

Strong: "You are a senior data engineer. Review this PostgreSQL query for correctness, performance, and adherence to our naming conventions (snake_case, no reserved words as column names). We're running on Postgres 15 with ~10M rows in the orders table. Point out: (1) any correctness issues, (2) missing indexes, (3) naming violations, (4) any simpler rewrites. Format your response as a numbered list."

XML tags for structured prompts

Claude is trained to recognize XML-style tags as semantic markers. Use them to clearly delineate sections of complex prompts:

EXAMPLE WITH XML TAGS
<role>You are a senior data modeling architect</role>

<context>
We are building a SaaS billing system for a B2B company.
- Multiple customers (tenants)
- Each customer has multiple users and multiple subscriptions
- Subscriptions have plans (monthly/annual) and add-ons
- We need to track usage events and generate invoices
</context>

<task>
Design a Logical Data Model for this billing system.
List the entities, their key attributes, and the relationships between them.
Identify all many-to-many relationships and how to resolve them.
</task>

<format>
For each entity: name, primary key, 5-7 key attributes
Relationships: entity1 β†’ relationship β†’ entity2 (cardinality)
Flag any M:N relationships
</format>

Chain-of-thought prompting

For complex reasoning tasks, ask Claude to think through the problem step by step before giving you the final answer. This dramatically improves accuracy on multi-step problems.

Few-shot examples

If you want Claude to produce output in a specific format or style, show it two or three examples first:

FEW-SHOT EXAMPLE FOR SQL DOCUMENTATION
Document each table in this format:
Example 1:
Table: customer
Purpose: Stores all registered customers.
Key columns: customer_id (PK), email (unique), created_at
Business rules: email must be verified before orders allowed.

Example 2:
Table: order
Purpose: Tracks each purchase transaction.
Key columns: order_id (PK), customer_id (FK), order_date, status
Business rules: status transitions: Pending→Shipped→Delivered only.

Now document these tables in the same format: [your tables]

Iterative refinement

Don't try to write the perfect prompt on the first try. Claude conversations are iterative:

  1. Start broad: "Write a Python class for database connection management"
  2. Refine: "Add context manager support so it works with `with` statements"
  3. Add edge cases: "Handle connection timeouts and automatic reconnection with exponential backoff"
  4. Test it: "Now write pytest tests for the reconnection logic"

What to avoid