Production infrastructure for AI agents
Website · Documentation · Guides · Core · Template · Discord
systemprompt-identifiers
Typed newtype identifiers (UserId, TraceId, AgentId, McpServerId, and more) for systemprompt.io AI governance infrastructure. Enforces type-safe IDs across every boundary in the MCP governance pipeline, preventing accidental mixing of different ID types at compile time.
Layer: Shared — foundational types/traits with no dependencies on other layers. Part of the systemprompt-core workspace.
Overview
Strongly-typed newtype wrappers for every domain identifier in systemprompt.io. Distinct ID types cannot be mixed at call sites; the compiler rejects passing a UserId where an AgentId is expected.
Layout
src/
├── lib.rs // crate root, re-exports
├── macros/ // define_id! / define_token! and helpers
│ ├── id.rs
│ ├── token.rs
│ ├── helpers.rs
│ └── mod.rs
├── db_value/ // database boundary types
│ ├── value.rs // DbValue enum
│ ├── to_value.rs // ToDbValue trait
│ ├── from_value.rs // FromDbValue trait + JsonRow
│ └── mod.rs
├── auth/ // ApiKeyId, ApiKeySecret, CloudAuthToken,
│ │ // DeviceCertId, JwtToken, SessionToken
│ └── …
├── error.rs // IdValidationError
├── headers.rs // HTTP header name constants
├── agent.rs // AgentId, AgentName, ExternalAgentId
├── ai.rs // AiGatewayPolicyId, AiQuotaBucketId,
│ // AiRequestId, AiSafetyFindingId,
│ // ConfigId, MessageId
├── client.rs // ClientId, ClientType
├── cloud.rs // CheckoutSessionId, PriceId, TransactionId
├── connection.rs // ConnectionId
├── content.rs // CategoryId, ContentId, FileId, SkillId,
│ // SourceId, TagId
├── context.rs // ContextId
├── email.rs // Email (validated)
├── execution.rs // ArtifactId, ExecutionStepId, LogId, TokenId
├── funnel.rs // EngagementEventId, FunnelId,
│ // FunnelProgressId
├── gateway_conversation.rs // GatewayConversationId
├── hook.rs // HookId
├── jobs.rs // JobName, ScheduledJobId
├── links.rs // CampaignId, LinkClickId, LinkId
├── locale.rs // LocaleCode
├── marketplace.rs // MarketplaceId
├── mcp.rs // AiToolCallId, McpExecutionId, McpServerId
├── oauth.rs // AccessTokenId, AuthorizationCode,
│ // ChallengeId, RefreshTokenId
├── path.rs // ValidatedFilePath
├── plugin.rs // PluginId
├── policy.rs // PolicyVersion
├── profile.rs // ProfileName (validated)
├── provider_request.rs // ProviderRequestId
├── roles.rs // RoleId
├── section.rs // SectionId
├── session.rs // SessionId, SessionSource
├── task.rs // TaskId
├── tenant.rs // TenantId
├── trace.rs // TraceId
├── url.rs // ValidatedUrl
├── user.rs // UserId
└── webhook.rs // WebhookEndpointId
Usage
[]
= "0.9.2"
use ;
// Known string value (literal, parsed input, DB row).
let user = new;
let agent = new;
// Mint a fresh UUID-backed identifier.
let task = generate;
// Mixing newtype IDs is a compile error.
// let broken: AgentId = user; // error[E0308]: mismatched types
println!;
Validated identifiers (Email, ProfileName, ValidatedUrl, ValidatedFilePath, AgentName, McpServerId) expose a fallible constructor:
use Email;
let email = try_new?;
Traits Implemented
All ID types implement Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize (#[serde(transparent)]), AsRef<str>, and Display. With the sqlx feature, every identifier also derives sqlx::Type for direct binding in query_as! macros.
Feature Flags
| Feature | Default | Description |
|---|---|---|
sqlx |
off | Derives sqlx::Type on every identifier for database binding. |
Dependencies
serde,serde_json— serialisationuuid— UUID generationschemars— JSON schema generationchrono— timestamps onDbValuethiserror—IdValidationErrorsqlx(optional) — database type derivation
License
BSL-1.1 (Business Source License). Source-available for evaluation, testing, and non-production use. Production use requires a commercial license. Each version converts to Apache 2.0 four years after publication. See LICENSE.
systemprompt.io · Documentation · Guides · Live Demo · Template · crates.io · docs.rs · Discord
Shared layer · Own how your organization uses AI.