SED Documentation
v1.0.5Getting Started with SED
SED (Semantic Entity Designs) is a production-grade platform that transforms your database into an AI-ready semantic layer with enterprise security, automatic business context resolution, and sophisticated guardrails. This guide shows you how to deploy a secure AI-database integration in minutes.
Installation
Production Setup Guide
Step 1: Initialize with Auto-Detection
Interactive setup with automatic domain detection (ecommerce, SaaS, finance, healthcare), connection pooling, business context resolution, and security configuration.
Step 2: Deploy Secure API Endpoints
Step 3: AI Agent Integration
Plan → Approve → Execute workflow with encrypted plan storage, risk assessment, and automatic business context resolution (user_id becomes "Customer Identifier").
Configuration
SED uses a simple JSON configuration file to manage your database connections and settings.
Production Features Activated
After running sedql init
, SED deploys a production-grade platform with enterprise security, intelligent business context, and sophisticated monitoring.
Enterprise Features Enabled
Security & Monitoring
Business Intelligence
Production Setup Complete
Core Concepts
SED is a community-first platform that provides AI with the infrastructure and business understanding it needs to work intelligently with your data. It's not a wrapper that uses AI - it's a tool that helps AI understand your business context while keeping you in control.
AI Infrastructure & Control
SED provides AI with the infrastructure it needs while keeping you in control. This includes rate limiting, PII detection, access control, and secure workflows that empower AI without compromising your data.
What SED Provides to AI:
- • Business Context: Understanding of your domain and business terminology
- • Data Access Control: Safe, controlled access to your database
- • Security Infrastructure: PII protection, rate limiting, and audit trails
- • Business Rules: Context about your data relationships and constraints
Business Intelligence for AI
SED automatically detects your business domain and maps technical database terms to business language. This helps AI understand the context and meaning behind your data.
Example: Technical to Business Mapping
Technical Names:
- • user_id
- • order_date
- • product_sku
- • revenue_amount
Business Names:
- • Customer ID
- • Purchase Date
- • Product Code
- • Sales Revenue
Community-First Architecture
SED runs entirely on your infrastructure with no cloud dependencies. Your data never leaves your machines, ensuring community ownership and data sovereignty.
Community Benefits:
- • Data Sovereignty: Your data stays on your infrastructure
- • No Vendor Lock-in: Run SED anywhere, anytime
- • Community Ownership: Open source with community-driven development
- • Local Control: All processing happens on your machines
CLI Commands
Essential CLI commands for production deployment, monitoring, and management of your AI-database platform.
sedql init
Production setup with automatic domain detection, connection pooling, security configuration, and business context resolution.
Usage
Production Features
- • Auto-Detection - Domain (ecommerce, SaaS, finance, healthcare)
- • Connection Pooling - Managed connections with health monitoring
- • Security Setup - Rate limiting, encryption, API key generation
- • Business Context - Technical-to-business name mapping
- • API Endpoints - /api/plan, /api/approve, /api/execute
- • Monitoring - Error tracking, schema change detection
Production Output
sedql build
Build or rebuild your semantic layer. Use this when your database schema changes or you want to regenerate everything.
Usage
What it does
- • Discovers all tables, views, and schemas
- • Analyzes foreign key relationships
- • Detects business logic patterns
- • Generates semantic mapping
- • Auto-generates business rules
- • Creates
semantic-layer.json
sedql query
Query your database using natural language. SED validates your request against business rules and executes the query.
Usage
What it does
- • Validates query against business rules
- • Applies security and compliance checks
- • Executes the query safely
- • Returns results with validation status
Output
Note: Natural language to SQL translation is currently in development. The query command validates and executes queries but uses basic pattern matching for now.
sedql validate
Validate your semantic layer and check for potential issues or improvements.
Usage
What it checks
- • Semantic layer file exists and is valid JSON
- • All referenced entities are present
- • Relationship mappings are consistent
- • Business logic patterns are properly applied
- • Business rules are valid
- • Database connection is still valid
sedql rules
Manage business rules for your semantic layer. List, enable, disable, add custom rules, and configure rules.
Usage
Filtering Options
Additional Commands
sedql sync
Sync semantic layer with database changes.
sedql context
Get semantic context for AI applications.
sedql export
Export your semantic layer and configuration in various formats.
sedql import
Import semantic layer configuration from a file.
sedql status
Show current SED status and configuration details.
sedql detect-changes
Detect and analyze schema changes in your database.
sedql diagnose
Diagnose database access and permission issues.
AI Integration Guide
SED provides a production-grade Plan → Approve → Execute workflow for AI agents. This guide shows you how to integrate the secure AI agent workflow with any AI platform, featuring encrypted plan storage, risk assessment, and automatic business context resolution.
Integration Overview
AI Agent Workflow Architecture
SED provides a secure, three-step workflow that separates AI planning from execution:
- • Plan - AI creates execution plan with business context and risk assessment
- • Approve - Human or system approval with full visibility into what will be executed
- • Execute - Secure execution with PII detection, access control, and audit logging
- • Monitor - Real-time health checks, error tracking, and schema change detection
Production Workflow
ChatGPT Agent Integration
Production Agent Implementation
Integrate ChatGPT with SED's secure plan-approve-execute workflow for production AI-database interactions.
Example ChatGPT Integration
Method 2: Function Calling Integration
For more advanced integration, use ChatGPT's function calling to validate queries through SED before execution.
LangChain Integration
Custom Tool Integration
Create a custom LangChain tool that uses SED for semantic search and query validation.
Using SED Tool in LangChain
Custom AI Integration
REST API Integration
For custom AI applications, you can create a REST API wrapper around SED commands.
Best Practices
Performance Optimization
- • Cache semantic layer context to reduce CLI calls
- • Use batch operations for multiple queries
- • Implement connection pooling for database access
- • Monitor query execution times and optimize slow queries
Security Considerations
- • Always validate queries before execution
- • Use business rules to enforce access controls
- • Implement rate limiting for API endpoints
- • Log all AI-generated queries for audit trails
Error Handling
- • Implement graceful fallbacks for SED failures
- • Provide meaningful error messages to users
- • Retry failed operations with exponential backoff
- • Monitor and alert on integration failures
Maintenance
- • Regularly update semantic layer when schema changes
- • Review and update business rules periodically
- • Monitor AI query patterns and optimize rules
- • Keep SED and dependencies up to date
API Reference
Enterprise Authentication & Security
Production-grade security with rate limiting, account lockout, and timing-safe authentication.
Security Features
- • Rate Limiting - Configurable requests per minute per client
- • Account Lockout - Automatic lockout after failed attempts
- • Timing-Safe Comparison - Prevents timing attacks on API keys
- • Client Tracking - IP + User-Agent based identification
GET /api/schema
Returns the semantic mapping (entities, attributes, relationships).
GET /api/rules
Returns active business rules/guardrails.
POST /api/plan
AI creates execution plan with business context resolution and risk assessment. Plans are encrypted and stored with expiration.
Plan Features
- • Risk Assessment - Automatic classification (low/medium/high)
- • Business Context - Technical-to-business name mapping
- • Encrypted Storage - AES-256-CBC encryption with IV
- • Automatic Expiration - Plans expire after configurable time
- • Client Tracking - Full audit trail of who created plans
Response Example
POST /api/approve
Marks a plan as approved (human or policy gate).
POST /api/execute
Securely executes approved plans with PII detection, access control, and comprehensive audit logging.
Execution Guardrails
- • PII Protection - Automatic detection and masking of sensitive data
- • Risk Blocking - High-risk queries blocked from execution
- • Access Control - Row/column/query-level permissions
- • Connection Pooling - Managed database connections with retry logic
- • Audit Logging - Complete execution trail for compliance
Response Example
Notes
- Run npx sedql build first to generate .sed/*.mapping.json and rules.
- Set DATABASE_URL on the server. Keys are not exposed to browsers.
- Keep SED_REQUIRE_API_KEY=false for local dev if you want zero friction; enable in staging/prod.
Business Rules Engine
SED's Business Rules Engine acts as a governance layer that ensures AI interactions with your database are safe, compliant, and follow your business logic. Rules can be manually created and are automatically enabled for immediate protection.
Business Rules Overview
What are Business Rules?
Business rules are automated policies that govern how AI can interact with your database. They act as a "bouncer" that validates, modifies, or blocks queries based on your business requirements.
Security Rules
- • PII Protection
- • Access Control
- • Data Privacy
- • Audit Logging
Business Logic
- • Metric Definitions
- • Required Joins
- • Data Validation
- • Calculation Rules
Rule Execution Flow
Rule Types
Access Policy Rules
Control who can access what data and when. These rules enforce security and compliance requirements.
Metric Definition Rules
Define how business metrics should be calculated. Ensures consistency across all AI-generated queries.
Join Rules
Ensure proper table relationships are maintained. Automatically adds required joins to queries.
Data Validation Rules
Enforce data quality standards and format requirements. Validates data before processing.
Auto-Generated Rules
Advanced Automatic Rule Generation
SED uses advanced AI-powered analysis to automatically generate comprehensive business rules based on your database schema, data patterns, and business domain. Rules are enabled by default for immediate protection - no manual setup required.
What Gets Auto-Generated
- • Advanced PII Protection - Multi-method detection with compliance mapping
- • Business Domain Rules - Domain-specific business logic and workflows
- • Advanced Relationship Rules - Foreign key, business logic, and workflow relationships
- • Business Metrics & KPIs - Automatic metric definition and calculation rules
- • Data Validation Rules - Constraint-based and business logic validation
- • Workflow Rules - Business process and workflow enforcement
- • Compliance Rules - GDPR, HIPAA, PCI DSS compliance enforcement
- • Access Control Rules - Role-based and context-aware permissions
- • Performance Rules - Query optimization and performance monitoring
Advanced Auto-Generation Process
- 1. Schema Analysis - Comprehensive database structure analysis
- 2. Business Domain Detection - Identifies e-commerce, SaaS, fintech, healthcare domains
- 3. Multi-Method PII Detection - Pattern matching, semantic analysis, data profiling, ML classification
- 4. Advanced Relationship Analysis - Foreign key, business logic, and workflow relationship detection
- 5. Business Logic Extraction - Automatic metric, validation, and workflow rule generation
- 6. Compliance Mapping - GDPR, HIPAA, PCI DSS requirement detection
- 7. Confidence Assessment - Intelligent confidence scoring for all detections
- 8. Rule Optimization - Performance and accuracy optimization
- 9. Auto-Enable - Production-ready rules enabled by default
Custom Rules
Creating Custom Rules
SED supports creating custom business rules to address your specific requirements. You can create rules from JSON files or use the interactive rule creation feature.
Custom Rule Example
Rule Management Commands
Rule Filtering Options
Rule Management
Managing Rules
Rule Priority System
Rules are executed in priority order (highest first):
- • 1000-900: Critical security rules
- • 800-700: Business logic rules
- • 600-500: Data quality rules
- • 400-300: Performance rules
- • 200-100: Audit and logging rules
Testing Rules
Test your business rules with sample queries to ensure they work as expected.
Advanced Features
Advanced PII Detection
- • Multi-Method Detection: Pattern matching, semantic analysis, data profiling, and ML classification
- • Compliance Mapping: Automatic GDPR, HIPAA, PCI DSS compliance requirements
- • Risk Assessment: Intelligent risk level classification (Low, Medium, High, Critical)
- • Context Analysis: Table and column context-aware detection
- • Sample Data Analysis: Real data profiling for accurate detection
Advanced Business Logic Detection
- • Domain Detection: Automatic e-commerce, SaaS, fintech, healthcare domain identification
- • Relationship Analysis: Advanced foreign key and business relationship detection
- • Metric Generation: Automatic business metric and KPI detection
- • Workflow Analysis: Business process and workflow pattern detection
- • Validation Rules: Automatic constraint and validation rule generation
Production-Ready Features
- • Confidence Scoring: Intelligent confidence assessment for all detections
- • Fallback Mechanisms: Graceful degradation to basic patterns
- • Performance Optimization: Timeout handling and efficient processing
- • Comprehensive Logging: Detailed audit trails and debugging information
- • Extensible Architecture: Easy to extend with new detection methods
SED now provides production-ready advanced business rules engine with sophisticated PII detection and comprehensive business logic analysis.
Database Support
SED supports multiple database systems with automatic schema discovery and semantic mapping.
PostgreSQL
Full support for PostgreSQL with advanced schema discovery including multiple schemas, views, and complex relationships.
Features
- • Multiple schema support (public, private, custom schemas)
- • View and materialized view discovery
- • Foreign key relationship analysis
- • Index and constraint detection
- • Partitioned table support
Connection Example
MySQL
Comprehensive MySQL support with automatic detection of tables, views, and relationships across different databases.
Features
- • Multi-database support
- • View and stored procedure discovery
- • Foreign key constraint analysis
- • Index and trigger detection
- • Character set and collation awareness
Connection Example
SQLite
Lightweight SQLite support perfect for development, testing, and small applications with file-based databases.
Features
- • File-based database support
- • Automatic table discovery
- • Foreign key relationship analysis
- • Index and constraint detection
- • Perfect for development and testing
Connection Example
Connection Options
Advanced connection options and configuration settings for different database environments.
Connection Parameters
Basic Options
Advanced Options
Environment Variables
Connection Security
Best Practices
- • Use environment variables for sensitive credentials
- • Enable SSL/TLS for production connections
- • Use dedicated database users with minimal required permissions
- • Regularly rotate database passwords
- • Never commit credentials to version control
Environment Variables
Advanced Usage
Production-grade features for enterprise deployments. Connection pooling, health monitoring, structured error handling, and advanced security configurations for mission-critical AI-database systems.
Connection Pooling & Performance
Enterprise Connection Management
SED includes production-grade connection pooling with automatic health monitoring, retry logic, and resource cleanup.
Connection Features
Performance Stats
Cache Implementation Example
Query Optimization
- • Batch Operations - Group multiple queries together
- • Connection Pooling - Reuse database connections
- • Query Analysis - Monitor slow queries
- • Index Optimization - Ensure proper database indexing
Token Reduction
- • Semantic Compression - Use concise entity names
- • Context Filtering - Only include relevant metadata
- • Lazy Loading - Load context on demand
- • Query Templates - Pre-define common query patterns
Custom Business Patterns
Creating Custom Patterns
Extend SED's business logic detection with domain-specific patterns for your industry or organization.
Loading Custom Patterns
Pattern Types
- • Calculation Patterns - Business formulas and metrics
- • Status Patterns - State transitions and flags
- • Relationship Patterns - Entity connections
- • Validation Patterns - Data quality rules
Pattern Matching
- • Exact Matching - Precise column name matches
- • Fuzzy Matching - Similar name variations
- • Regex Patterns - Complex pattern matching
- • Context Matching - Table and column context
Schema Evolution
Managing Database Changes
Keep your semantic layer synchronized with database schema changes. SED provides tools to detect, analyze, and apply schema evolution safely.
Change Types
- • New Tables - Automatically detected and mapped
- • New Columns - Added to existing entities
- • Removed Tables/Columns - Marked as deprecated
- • Type Changes - Updated data type mappings
- • Relationship Changes - Updated foreign key mappings
Version Management
- • Automatic Backups - Previous versions saved
- • Rollback Support - Revert to previous versions
- • Change Logging - Track all schema changes
- • Breaking Change Detection - Identify risky changes
CI/CD Integration
Integrate schema evolution into your deployment pipeline for automated semantic layer updates.
Monitoring & Analytics
Performance Monitoring
Monitor SED performance, track usage patterns, and identify optimization opportunities.
Key Metrics
- • Query Performance - Execution times and throughput
- • Rule Effectiveness - Hit rates and impact
- • Cache Performance - Hit rates and efficiency
- • Error Rates - Failed queries and rule violations
- • Usage Patterns - Most common queries and entities
Alerting
- • Performance Thresholds - Slow query alerts
- • Error Rate Monitoring - High failure rate alerts
- • Rule Violations - Security breach notifications
- • Schema Changes - Breaking change alerts
Integration with Monitoring Tools
Connect SED metrics to your existing monitoring infrastructure for comprehensive observability.
Examples & Use Cases
Real-world examples of how SED can be used to solve common AI-database integration challenges. Each example includes schema overview, business requirements, setup instructions, and integration patterns.
E-commerce Platform
Business Requirements
- • AI-powered product recommendations
- • Customer behavior analysis
- • Revenue and conversion tracking
- • PII protection for customer data
- • Inventory and order management
Database Schema Overview
Business Rules Setup
AI Integration Example
SaaS Platform
Business Requirements
- • Customer churn prediction
- • Feature usage analytics
- • MRR (Monthly Recurring Revenue) tracking
- • User engagement metrics
- • Subscription management
Database Schema Overview
Business Rules Setup
AI Integration Example
Healthcare System
Business Requirements
- • HIPAA compliance and PHI protection
- • Patient outcome analysis
- • Treatment effectiveness tracking
- • Appointment scheduling optimization
- • Medical record management
Database Schema Overview
Business Rules Setup
AI Integration Example
Financial Services
Business Requirements
- • Fraud detection and prevention
- • Risk assessment and compliance
- • Transaction monitoring
- • Customer portfolio analysis
- • Regulatory reporting