Constitution Core
Shared AI safety infrastructure for all Governor HQ constitutions
What is Constitution Core?
@the-governor-hq/constitution-core is the foundational package that powers all Governor HQ domain-specific constitutions (wearables, BCI, therapy).
It provides:
- Validators — Enforce AI safety rules at authoring time
- Middleware — Runtime validation for API responses
- CLI Tools — Command-line utilities for validation
- Evaluation System — Test AI safety compliance
- Base MCP Server — Foundation for domain packages
Why Core Exists
Each domain (wearables, BCI, therapy) has specific safety rules, but they all share common infrastructure needs:
| Need | Core Solution |
|---|---|
| Validate code against safety rules | Validators (medical-claims, authoritative-language, etc.) |
| Catch unsafe AI responses at runtime | Middleware (validation interceptors) |
| Test compliance before deployment | Evaluation system with LLM judge |
| Command-line validation | CLI tools (governor-validate) |
| Consistent MCP server structure | Base MCP server class |
Core = no duplication. Safety infrastructure is built once, shared everywhere.
Package Structure
@the-governor-hq/constitution-core/
├── src/
│ ├── validators/ # Safety rule validators
│ │ ├── medical-claims.ts
│ │ ├── authoritative-language.ts
│ │ ├── diagnosis.ts
│ │ └── ...
│ ├── middleware/ # Runtime validation
│ │ ├── response-validator.ts
│ │ └── ...
│ ├── base-mcp-server.ts # Base MCP server
│ └── index.ts
├── bin/
│ └── governor-validate.js # CLI tool
├── evals/ # Evaluation system
│ ├── eval-runner.js
│ ├── llm-judge.js
│ └── test-cases/
└── examples/ # Usage examplesQuick Example
Using Validators
import { validateMedicalClaims } from '@the-governor-hq/constitution-core';
const code = `
return "This smartwatch can detect heart attacks before they happen.";
`;
const result = validateMedicalClaims(code);
if (!result.valid) {
console.error('Validation failed:', result.violations);
// Violations: ["Disease diagnosis claim detected"]
}Using Runtime Middleware
import { createResponseValidator } from '@the-governor-hq/constitution-core';
const validator = createResponseValidator({
enableMedicalClaimsCheck: true,
enableAuthoritativeLanguageCheck: true
});
// Wrap API responses
const aiResponse = await getAIResponse(userQuery);
const validatedResponse = await validator.validate(aiResponse);
if (!validatedResponse.safe) {
// Sanitize or reject unsafe response
return validatedResponse.sanitized;
}Using CLI Tool
# Validate a file
npx governor-validate src/insights.ts
# Validate entire directory
npx governor-validate src/
# Strict mode
npx governor-validate --strict src/Who Uses Core?
Domain Packages
All Governor HQ domain packages depend on core:
// @the-governor-hq/constitution-wearables/package.json
{
"dependencies": {
"@the-governor-hq/constitution-core": "^3.0.4"
}
}They extend core validators with domain-specific rules.
Your Application
You can use core directly:
npm install @the-governor-hq/constitution-coreOr use domain-specific packages (wearables, BCI, therapy) which include core automatically.
Key Features
Validators
Enforce safety rules at authoring time:
- Medical diagnosis claims
- Authoritative vs. supportive language
- Emergency response protocols
- Supplement dosing safety
- And 20+ more
See: Validators Guide
Middleware
Runtime validation for production:
- Intercept AI responses before showing users
- Sanitize unsafe content
- Log violations
- Fail-safe defaults
See: Middleware Guide
CLI Tools
Command-line validation:
governor-validate src/**/*.ts --strictSee: CLI Tools
Evaluation System
Test AI safety compliance:
npm run eval
npm run eval:critical
npm run eval:medicalUses GPT-4 as an LLM judge to test edge cases.
See: Evaluation System
Base MCP Server
Foundation for domain MCP servers:
import { BaseMCPServer } from '@the-governor-hq/constitution-core';
class WearablesMCPServer extends BaseMCPServer {
getContext() {
return {
...super.getContext(),
domain: 'wearables',
rules: this.wearablesRules
};
}
}See: Runtime Validation
Installation
# Install core directly
npm install @the-governor-hq/constitution-core
# Or use a domain package (includes core)
npm install @the-governor-hq/constitution-wearables
npm install @the-governor-hq/constitution-bci
npm install @the-governor-hq/constitution-therapyDocumentation
- Getting Started — Installation and first validation
- Validators — All available safety validators
- Middleware — Runtime validation setup
- CLI Tools — Command-line usage
- Runtime Validation — Runtime validator usage
- Evaluation System — Testing safety compliance
Version
Current version: 3.0.4
Updates:
- Comprehensive validator suite
- LLM-based evaluation system
- Runtime middleware
- CLI tooling
- TypeScript migration complete
Contributing
Core is the foundation of Governor HQ. Changes here affect all domain packages.
See CONTRIBUTING.md (opens in a new tab)
Summary
Constitution Core provides:
- ✅ Safety validators (20+ rules)
- ✅ Runtime middleware
- ✅ CLI tools
- ✅ Evaluation system
- ✅ Base MCP server
Used by:
- All domain packages (wearables, BCI, therapy)
- Your application (direct usage)
Build safe AI features with shared, tested infrastructure.