Project Constraints and Validation
Copy page
How the Inkeep Agent Framework ensures data integrity with project constraints
Project Constraints and Validation
The Inkeep Agent Framework implements multiple layers of validation to ensure that all agent graphs and resources are associated with valid projects.
Database-Level Constraints
Foreign Key Constraints
All tables that reference projects include foreign key constraints to ensure referential integrity:
This ensures that:
- No data can be inserted for non-existent projects
- Deleting a project cascades to remove all associated resources
- Data integrity is maintained at the database level
Tables with Project Constraints
The following tables have foreign key constraints to the projects
table:
agents
- Agent configurationsagent_relations
- Relationships between agentsagent_graphs
- Graph definitionstools
- Tool configurationscontext_configs
- Context configurationsexternal_agents
- External agent referencesconversations
- Chat conversationsmessages
- Chat messagestasks
- Task records- And more...
Runtime Validation
CLI Validation
The Inkeep CLI validates project existence before pushing graphs:
Data Access Layer Validation
The core package provides validation utilities for runtime checks:
Wrapped Operations
Data access functions can be wrapped with automatic validation:
Implementation Details
Schema Definition
Enabling Foreign Keys in SQLite
SQLite requires explicit enabling of foreign key constraints:
This should be set when creating the database connection:
Error Handling
When a constraint violation occurs, appropriate error messages guide users:
CLI Error
Database Error
Best Practices
- Always validate at multiple levels: Database constraints, runtime validation, and UI validation
- Provide clear error messages: Help users understand what went wrong and how to fix it
- Offer solutions: When a project doesn't exist, offer to create it
- Use transactions: Ensure atomicity when creating projects and related resources
- Test constraints: Verify that constraints work as expected in tests
Migration Guide
For existing databases without constraints:
- Backup your database before applying migrations
- Check for orphaned data: Find resources referencing non-existent projects
- Clean up orphaned data or create missing projects
- Apply foreign key constraints using migrations
- Enable foreign key enforcement in your database connection
Benefits
- Data Integrity: Prevents orphaned data and maintains consistency
- Clear User Experience: Users are guided to create projects when needed
- Easier Debugging: Constraint violations are caught early
- Simplified Cleanup: Cascading deletes remove all related data
- Better Documentation: Constraints document relationships in the schema