DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
Status
| State | Draft |
| Discussion Thread | |
| Vote Thread | |
| Vote Result Thread | |
| Progress Tracking (PR/GitHub Project/Issue Label) | |
| Date Created |
|
| Version Released | |
| Authors |
Background & Motivation
In today's evolving data landscape, organizations face significant challenges:
- Schema Drift Detection: Breaking changes between upstream and downstream systems consume significant engineering time
- Multi-Cloud Complexity: Data scattered across AWS, GCP, Azure with different formats (Iceberg, Delta Lake, Parquet, PostgreSQL, etc.)
- Data Quality at Scale: Context-aware validation that understands business rules, not just syntax
- AI Context Requirements: Providing accurate data context to AI/ML models and agents for reliable insights
Real-World Pain Points:
- Schema mismatches between producers and consumers causing pipeline failures
- Manual data quality checks that don't scale with data volume or complexity
- Fragmented tooling for accessing data across cloud providers and storage formats
- Lack of intelligent validation that understands business context
This proposal leverages Airflow's strengths (production reliability, 1000+ integrations, governance) while adding AI-native capabilities for intelligent data operations.
Core Proposal: Specialized LLM Operators with Rich Context Integration
Based on Pydantic AI's capabilities, while it provides excellent agent framework, multi-model support, and structured outputs, it lacks:
- Airflow Production Integration: No native connection management, XCom, DAG context, or retry logic
- Context-Aware Safety: No built-in protection against dangerous SQL operations or file modifications
- Automatic Context Injection: No integration with Airflow's 500+ hooks for schema/metadata discovery
- Workflow-Native Features: No approval workflows, asset integration, or Airflow monitoring
An example view of how Operators look like below:
1. Specialized LLM Operators with Built-in Protection & Context
2. Task Decorators for Dynamic AI Workflows
Each LLM operator has a corresponding decorator for more flexible, Pythonic workflows:
Benefits of Decorator Approach:
- Dynamic prompts based on runtime conditions
- Custom pre-processing logic before LLM calls
- Context enrichment from external systems
- Conditional logic for different scenarios
- Pythonic workflow familiar to Airflow users
- Full XCom integration for passing data between tasks
3. Rich Context Injection Examples
SQL Operator Context (via DbApiHook integration):
3. Operator-Specific Safety & System Prompts
SQL Operator Built-in Protection:
SAFETY RULES:
- NEVER generate DROP, TRUNCATE, DELETE without WHERE, or ALTER statements
- Always use proper JOIN syntax for this database type
- Respect column types and constraints provided in schema
- Use database-specific functions when available
CONTEXT: You have access to schema info, sample data, and dialect features.
Generate optimized, safe queries that work with {database_type} version {version}."""
File Operator Built-in Protection:
SAFETY RULES:
- ONLY read and analyze files, NEVER modify or delete
- Respect file size limits and memory constraints
- Generate efficient queries for large datasets
CONTEXT: File has {estimated_rows} rows, {file_size_mb}MB, partitioned by {partitioning}."""
4. Schema Comparison with Multi-Database Context
# Cross-system schema drift detection
schema_drift = LLMSchemaCompareOperator(
task_id="detect_schema_drift",
data_sources=[customer_s3, customer_postgres, customer_snowflake],
prompt="Identify schema mismatches that would break data loading between systems",
# Automatically gets context from each system:
# - S3: Parquet schema, partitioning, file stats
# - PostgreSQL: Table schema, constraints, indexes
# - Snowflake: Column types, clustering keys, data sharing info
)
5. Unified Data Access with Apache DataFusion
A new AnalyticsOperator that provides unified access to multi-cloud data:
from airflow.providers.ai.operators import AnalyticsOperator
# Execute queries across different storage systems uniformly
analytics_task = AnalyticsOperator(
task_id="cross_cloud_analysis",
query="{{ ti.xcom_pull(task_ids='quality_check') }}", # LLM-generated query
data_sources=[customer_s3, orders_gcs, inventory_azure], # Multi-cloud
engine="datafusion", # High-performance query engine
output_format="parquet",
output_location="s3://results/analysis/"
)
Why Apache DataFusion for AI Workloads:
Based on Wren AI's experience, DataFusion provides significant advantages for AI-driven data analysis:
- Exceptional Performance: Query and perform aggregation operations on approximately 50 million records in under 10-15 seconds on single-node operations
- Multi-Cloud Native: Built-in support for S3, GCS, Azure Blob Storage without additional configuration
- Multi-Format Support: Native handling of Parquet, JSON, CSV, Avro, Iceberg, Delta Lake formats
- Cost Effective: Eliminates need for expensive distributed compute frameworks like Spark for many AI use cases
- SQL Dialect Unification: Provides unified SQL interface across different storage systems, crucial for AI agents
- Rust Performance: High-performance query engine optimized for the analytical workloads AI agents typically generate
6. Human-in-the-Loop Integration Options
We propose both embedded and separate HITL patterns:
Option A: Embedded HITL
Option B: Separate HITL Steps
Complete Workflow Example
Here's a real-world scenario combining all components:
Evolution Path: From LLMOperator to AITask
While we start with SQL generation, the architecture supports broader AI workflows:
# Future: General AI task abstraction
process_customer_churn = AITask(
task_id="analyze_churn_patterns",
objective="Identify customers at risk of churning and recommend actions",
resources={
"customer_data": snowflake_conn,
"email_system": sendgrid_conn,
"ml_platform": sagemaker_conn
},
constraints={"budget": "$50", "privacy": "pii_protected"},
output_model=ChurnAnalysisReport
)
Technical Implementation Details
Core Components
- Specialized LLM Operators & Decorators
- LLMSQLQueryOperator / @task.llm_sql_query: Natural language to SQL generation
- LLMSchemaCompareOperator / @task.llm_schema_compare: Schema drift detection between systems
- LLMDataQualityOperator / @task.llm_data_quality: Context-aware data validation query generation
- LLMFileAnalysisOperator / @task.llm_file_analysis: File content analysis and processing
Decorator Benefits:
- Dynamic prompt generation based on runtime conditions
- Custom pre-processing logic before LLM calls
- Context enrichment from external systems (business rules, calendars, alerts)
- Conditional logic for different operational scenarios
Enhanced Asset System
# Proposed Asset structure evolution
class Asset:
name: str
uri: str
conn_id: Optional[str] = None # Direct connection reference
schema: Optional[Dict[str, str]] = None # Structured schema
sensitivity: Optional[str] = None # pii, sensitive, public
format: Optional[str] = None # parquet, json, csv, etc.
statistics: Optional[Dict] = None # Row counts, update times
extra: Dict[str, Any] = field(default_factory=dict) # Backward compatibility
AnalyticsOperator with DataFusion
- Unified interface for multi-cloud data access across S3, GCS, Azure Blob Storage
- Native handling of Parquet, Iceberg, Delta Lake, JSON, CSV, Avro formats
- High-performance processing: 50M+ records in 10-15 seconds on single node(This is from my experiments)
- Cost-effective alternative to Spark for AI-generated analytical queries
- SQL dialect unification - write once, run anywhere
- DataFusion table provider supports integrating existing databases like sqlite, postgres. A good option here is using datafusion-table-providers. https://github.com/datafusion-contrib/datafusion-table-providers
Flexible HITL Integration
- Embedded approval within operators (require_approval=True)
- Separate ApprovalOperator with query modification capabilities
- Configurable timeout and escalation policies
Implementation Approach
Phase 1: Standalone Provider - No Core Changes Required
- Provider: apache-airflow-providers-ai (0.x releases for iteration)
- Core LLM operators with Pydantic AI integration
- Schema detection using existing connection types and hooks (no core modifications needed)
- DataFusion-based AnalyticsOperator for unified data access ( Users can extend this interface and provide their own implementation for querying if they don't prefer datafusion, eg use; duckdb)
- Asset integration using current Asset.extra for metadata (backward compatible)
- Validations: Query validation and safety analysis
Key Benefit: Can iterate rapidly on operator design and context injection without any core Airflow changes. All functionality works through existing connection and hook infrastructure.
Phase 2: Production Features
- Advanced HITL workflows with modification capabilities
- Performance optimization and caching
- Enhanced Asset metadata (if community feedback supports core changes)
Phase 3: Core Integration
- Only if Phase 1 proves valuable: Consider core Asset enhancements
- Provider-specific AI capabilities in existing providers
- Community tool ecosystem and standards
Why This Matters
For Airflow:
- Positions Airflow at the center of AI-powered data infrastructure
- Makes Airflow more data-aware: Enhanced Asset metadata creates richer data context and lineage
- Drives Asset adoption: Users get immediate value from defining Assets with schema and sensitivity metadata
- Leverages our unique strengths in production reliability and 1000+ provider ecosystem
For Users:
- Democratizes data access - business users describe intent in natural language
- Data engineers maintain governance, reliability, and safety through built-in protections
- Rich data context: Assets become intelligent, carrying schema, business rules, and sensitivity information
For the Industry: Creates the missing bridge between AI capabilities and production data infrastructure while making data assets first-class citizens in AI workflows.