Schemas
Shared Zod schemas and TypeScript types for the consensus-tools monorepo.
Overview
@consensus-tools/schemas is the contract layer for the entire monorepo. It exports Zod schemas for runtime validation and TypeScript types for compile-time safety. Every other package depends on it, and it has zero internal dependencies.
Installation
Quick start
Validate untrusted data at runtime using any exported Zod schema:
Use TypeScript types alone (zero runtime cost) for typed function signatures:
API reference
jobSchema
Validates a full job object including mode, status, constraints, and escrow policy.
jobPostInputSchema / voteInputSchema
Validate API endpoint inputs. Each endpoint has a matching input schema.
consensusPolicyConfigSchema
Validates consensus policy configuration objects.
Available policy types: FIRST_SUBMISSION_WINS, HIGHEST_CONFIDENCE_SINGLE, APPROVAL_VOTE, OWNER_PICK, TOP_K_SPLIT, MAJORITY_VOTE, WEIGHTED_VOTE_SIMPLE, WEIGHTED_REPUTATION, TRUSTED_ARBITER.
guardEvaluateInputSchema / guardResultSchema
Validate guard evaluation inputs and results.
Examples
Exports reference
| Domain | Schemas | Types |
|---|---|---|
| Policy | consensusPolicyTypeSchema, approvalVoteConfigSchema, consensusPolicyConfigSchema, slashingPolicySchema | ConsensusPolicyType, ApprovalVoteConfig, ConsensusPolicyConfig, SlashingPolicy |
| Job | jobModeSchema, jobStatusSchema, jobConstraintsSchema, escrowPolicySchema, jobSchema | JobMode, JobStatus, JobConstraints, EscrowPolicy, Job |
| Submission | submissionStatusSchema, submissionSchema | SubmissionStatus, Submission |
| Vote | voteTargetTypeSchema, voteSchema | VoteTargetType, Vote |
| Resolution | resolutionSchema | Resolution |
| Ledger | ledgerEntryTypeSchema, ledgerEntrySchema | LedgerEntryType, LedgerEntry |
| Guard | guardTypeSchema, guardDecisionSchema, guardVoteSchema, weightedGuardVoteSchema, guardPolicySchema, guardEvaluateInputSchema, guardResultSchema | Matching types + VoteTally |
| Agent | agentKindSchema, agentStatusSchema, agentSchema, agentConfigSchema | AgentKind, AgentStatus, Agent, AgentConfig |
| Participant | participantSubjectTypeSchema, participantStatusSchema, participantSchema | ParticipantSubjectType, ParticipantStatus, Participant |
| Workflow | workflowStatusSchema, workflowSchema, workflowRunSchema, cronScheduleSchema | WorkflowStatus, Workflow, WorkflowRun, CronSchedule |
| HITL | hitlModeSchema, hitlStatusSchema, hitlApprovalSchema, humanDecisionSchema | HitlMode, HitlStatus, HitlApproval, HumanDecision |
| Telemetry | telemetryEventTypeSchema, telemetryEventSchema, traceSpanSchema | TelemetryEventType, TelemetryEvent, TraceSpan |
| Config | consensusToolsConfigSchema | ConsensusToolsConfig |
| Storage | storageStateSchema | StorageState |
| Common | claimStatusSchema, bidSchema, assignmentSchema, auditEventSchema, diagnosticEntrySchema | ClaimStatus, Bid, Assignment, AuditEvent, DiagnosticEntry |
| Inputs | jobPostInputSchema, claimInputSchema, submitInputSchema, voteInputSchema, resolveInputSchema | Matching types |
| Policy Assignment | policyAssignmentSchema, consensusVoteSchema | PolicyAssignment, ConsensusVote |
| Resolver | -- | ConsensusInput, ConsensusResult, PolicyResolver |
Zero-cost types
All Zod schemas export a matching TypeScript type via z.infer. Import with type to avoid any runtime cost when you only need compile-time checking.
Related
- Consensus Policies -- policy types that schemas validates
- Guards package -- consumes guard schemas for evaluation
- Architecture -- how schemas fits into the overall system