Using Predefined SQL for LLM-Based Agents

Overview

This whitepaper explores the practical value of predefined SQL structures—like those created using AltaSQL—for enabling accurate, secure, and semantically aligned SQL generation by LLM-based agents in enterprise Snowflake environments.

Introduction

LLMs (Large Language Models) are powerful tools for generating SQL from natural language prompts. However, when left to generate queries from scratch in complex data environments, LLMs often hallucinate table names, misinterpret business logic, or create unsafe SQL. The antidote? Predefined SQL building blocks.

AltaSQL makes this possible by transforming existing Snowflake assets into structured, tagged, and discoverable SQL components that LLM-based agents can use safely and intelligently.

1. Predictability Over Creativity

LLMs operate on probabilistic logic. While this allows impressive flexibility, enterprise SQL demands precision. Predefined SQL—via AltaSQL View Definitions—anchors LLMs to validated queries and business rules. This increases:

 Trust in generated results
 Interpretability of logic
 Safety in production environments

2. Bounded Reasoning Space

LLMs perform better when the solution space is constrained. Instead of navigating a vast, undocumented Snowflake schema, agents are guided by AltaSQL View Definitions contained in meta-data repositories. View Definitions contain two types of meta-data:

 Rows that generate columns using column alias syntax for generated SQL. Properties include:
 Column ALIAS names, typically in natural language
 Data source column names
 Column comments
 AltaSQL data type, e.g., EXPRESSION
 Default source objects i.e., database, schema and object name
 Table Alias
 Snowflake Object Type
 Dynamic Data Masking Policy

.

  AltaSQL Tags, both user created and pre-defined by AltaSQL[1], containing:
 Modular components for constructing SQL statement, e.g. FROM_CLAUSEs
 “Semantic” tags, providing both human and LLM readable context information including:
· Enhanced documentation
· Environment guidance/rules such as warehouse, roles, etc.
· “Ready-to-Run” existing SELECT statements and scripts from existing solutions
· “Ready-to-Generate” SBLD_SELECT function calls complete with pre-set FROM_CLAUSE and POST_FROM_CLAUSE arguments
 AltaSQL Tags ensure agents:
 Adhere to naming and access standards
 Avoid unnecessary or incorrect joins

This bounded reasoning space yields more accurate, context-aware results with less risk.

3. Semantic Alignment Through Meta-data

AltaSQL Tags enrich each View Definition with semantic tags such as:

 Question Tags
 e.g., what question(s) can be addressed
 Business Purpose Tags
 e.g., “Customer lifetime value analysis”, “Sales pipeline forecast”
 Functional Area Tags
 e.g., “HR Analytics”, “Procurement Operations”, “Risk Management”
 Strategic Initiative Tags
 Links the view to company-wide initiatives (e.g., “Digital Transformation”, “Cost Optimization 2025”)
 Key Metric Tags
 Highlights key metrics the view supports (e.g., “Revenue by Region”, “NPS Score”, “Churn Rate”, etc.).

These tags allow LLMs to not just produce SQL—but to build business-aligned SQL. This marks the evolution from query automation to semantic understanding.

4. LLMs as Agents, Not Authors

When fed predefined SQL and AltaSQL context, LLM-based agents shift from being risky, one-off SQL generators to reliable, repeatable co-pilots. AltaSQL provides three options for producing SELECT statements:

 Compose logic modularly by selecting appropriate FROM_CLAUSE and either selecting POST_FROM_CLAUSE or dynamically generating the POST_FROM_CLAUSE
 Use Ready-to-Generate SBLD_SELECT function call
 Use Ready-to-Run SELECT statement

This is a more sustainable, scalable, and governable approach to AI in analytics.

Conclusion

The value of predefined SQL lies in its ability to convert unstructured prompts into structured, governed execution. AltaSQL delivers this foundation, enabling LLM-based agents to operate with enterprise-grade precision, safety, and context. Using pre-defined SQL enables improving, testing and adding new solutions to existing semantic intention and reusability.

With AltaSQL, you’re not just teaching an AI to write SQL—you’re giving it a language your business already understands.

Learn More at AltaSQL.io.

#AltaSQL #Snowflake #SQLAutomation #DataProductivity #MetadataManagement

#EnterpriseAI #AIAssistedAnalytics #AIReadyData. #SemanticAI

#IntelligentSQL.AIProductivity #AIForDataTeams #DataCopilot #TrustedAI

  1. AltaSQL currently defines 28 AltaSQL Tag Classes

Leave a Comment

Discover more from AltaSQL for Snowflake

Subscribe to get the latest posts sent to your email.

More
articles

Scroll to Top