Availability
| Edition | Deployment Type |
|---|---|
| Community & Enterprise | Self-Managed, Hybrid |
Object Hooks Plugin Guide
Object Hooks are a powerful plugin capability that allows you to intercept and control CRUD operations on AI Studio objects before they are saved to the database. This enables validation, enrichment, policy enforcement, and integration with external systems.Overview
Object Hooks provide plugins with the ability to:- Validate objects before creation or modification
- Reject operations that don’t meet requirements
- Enrich objects with additional data
- Enforce policies (security, compliance, naming conventions)
- Integrate with external systems (ticketing, approval workflows)
- Audit changes with custom metadata
- Transform data before it reaches the database
Supported Objects
Object Hooks work with four core AI Studio object types:| Object Type | Description | Common Use Cases |
|---|---|---|
| llm | LLM Providers | Validate endpoints, enforce HTTPS, check privacy scores |
| datasource | Data Sources | Validate connections, enforce security policies |
| tool | External Tools | Validate OpenAPI specs, check endpoints |
| user | Users | Enforce naming conventions, integrate with LDAP/AD |
Hook Types
Each object type supports six hook types that fire at different points in the lifecycle:| Hook Type | When It Fires | Can Block? | Can Modify Object? | Common Use Cases |
|---|---|---|---|---|
| before_create | Before object creation | Yes | Yes | Validation, default values, policy enforcement |
| after_create | After object creation | No | No | Notifications, external system sync, audit logging |
| before_update | Before object update | Yes | Yes | Change validation, approval workflows |
| after_update | After object update | No | No | Change notifications, audit trails |
| before_delete | Before object deletion | Yes | No | Prevent deletion, cleanup checks |
| after_delete | After object deletion | No | No | Cleanup external resources, notifications |
before_*hooks can block operations by settingAllowOperation: falseafter_*hooks are informational only and cannot block operations- Only
before_createandbefore_updatecan modify the object itself - All hooks can add plugin metadata that is stored with the object
Implementing Object Hooks
Step 1: Implement ObjectHookHandler Interface
Step 2: Register Your Hooks
Declare which object types and hook types your plugin handles:Expandable
- Lower priority numbers execute first (e.g., priority 10 runs before priority 50)
- Use priorities to control execution order when multiple plugins handle the same hook
- Common priority ranges:
1-10: Critical validation that should run first11-49: Standard validation and policy enforcement50-89: Enrichment and transformation90-99: Logging and audit (should run last)
Step 3: Handle Hook Invocations
Process the hook request and return a response:Expandable
Hook Request Structure
TheObjectHookRequest provides context about the operation:
ObjectJson: The object being created/updated/deleted (JSON string)PreviousJson: Previous object state for update operations (compare before/after)ObjectID: 0 for create operations, actual ID for update/deleteOperationId: Unique ID for correlating logs and debugging
Hook Response Structure
Your plugin returns anObjectHookResponse:
1. Allow Without Changes
2. Allow With Metadata
3. Block Operation
4. Modify Object (before_create/before_update only)
Expandable
Complete Example: LLM Validator
This example validates LLM objects to enforce security and quality policies:Expandable
Use Case Examples
1. Enforce HTTPS for LLM Endpoints
Expandable
2. Auto-Enrich Objects with Defaults
Expandable
3. Integration with External Approval System
Expandable
4. Audit Trail with Change Tracking
Expandable
5. Prevent Deletion of Active Resources
Expandable
Best Practices
Validation
- Fail fast: Perform quick checks first to avoid expensive operations
- Clear messages: Provide specific, actionable error messages
- Log verbosely: Use
ctx.Services.Logger()for debugging - Handle errors: Always check JSON unmarshaling errors
Performance
- Keep hooks lightweight: Hooks run synchronously in the request path
- Cache lookups: Use KV storage for repeated validations
- Timeout external calls: Use context timeouts for external APIs
- Async for after_ hooks: Use goroutines for non-critical after_ hook work
Security
- Validate all inputs: Never trust object data
- Check permissions: Use
req.UserIdto enforce RBAC - Sanitize output: Don’t leak sensitive data in error messages
- Audit changes: Log all modifications for compliance
Metadata
- Use consistent keys: Establish naming conventions (e.g.,
plugin_name:key) - Version your metadata: Include plugin version for debugging
- Don’t overload: Keep metadata concise, use external storage for large data
- Document schema: Document what metadata your plugin adds
Error Handling
- Block vs. log: Use
AllowOperation: falsesparingly - Helpful messages: User sees
Messagefield, make it clear - Differentiate errors: Use
RejectionReasonfor why it failed - Return nil error: Return
(response, nil)unless plugin crashes
Debugging Object Hooks
Enable Verbose Logging
Test with hook-test-plugin
Thehook-test-plugin example provides a comprehensive testing UI:
- Test all 24 hook combinations (4 objects × 6 hook types)
- Configure behavior per hook (allow/reject/modify/metadata)
- View real-time hook invocations
- Automated test runner
Common Issues
Issue: Hook not firing- Check
GetObjectHookRegistrations()returns correct object types - Verify plugin is installed and enabled in AI Studio
- Check plugin logs for initialization errors
- Only
before_createandbefore_updatecan modify objects - Must set
Modified: trueand provideModifiedObjectJson - Verify JSON marshaling succeeds
- Check all registered plugins for the same hook
- Lower priority plugins run first
- Review plugin logs for rejection reasons
Manifest Configuration
Object hooks must be declared in your plugin manifest:Complete Working Examples
LLM Validator
examples/plugins/studio/llm-validator/
- Validates LLM endpoints (HTTPS enforcement)
- Blocks based on vendor or privacy score
- Requires description field
- Adds validation metadata
Hook Test Plugin
examples/plugins/studio/hook-test-plugin/
- Comprehensive testing of all 24 hook combinations
- Configurable behavior per hook type
- Web UI for testing and configuration
- Automated test runner