Context
Working with complex data structures.
Problem
Exposing full schema upfront is overwhelming; too little is insufficient.
Solution
Layer discovery progressively:
- Layer 1: list_tables() - What exists
- Layer 2: describe_table(name) - Field details
- Layer 3: sample_data(table, limit) - See examples
- Layer 4: get_query_hints(table) - Usage tips
- Layer 1: list_tables() - What exists
- Layer 2: describe_table(name) - Field details
- Layer 3: sample_data(table, limit) - See examples
- Layer 4: get_query_hints(table) - Usage tips
Examples
Python
# Layer 1: What tables exist?
@tool
def list_tables() -> list[str]:
"""List all database tables."""
# Layer 2: What fields does a table have?
@tool
def describe_table(table_name: str) -> TableSchema:
"""Get schema for a table. Call list_tables() first."""
# Layer 3: What does the data look like?
@tool
def sample_rows(table_name: str, limit: int = 5) -> list[dict]:
"""Get sample rows. Call describe_table() first.""" Considerations
- Each layer should suggest the next step
- Include examples at each level
- Consider caching schema information