Skip to main content

# Production-Ready
AI Safety

Integrate Tractatus framework into your AI systems with practical guides, code examples, and battle-tested patterns for real-world deployment.

Quick Start Guide View Documentation

## Integration Approaches

### Full Stack

Complete framework integration for new AI-powered applications. All five services active with persistent instruction storage.

- Instruction classification & storage
- Cross-reference validation
- Boundary enforcement
- Context pressure monitoring

Best for: New projects, greenfield AI applications

### Middleware Layer

Add Tractatus validation as middleware in existing AI pipelines. Non-invasive integration with gradual rollout support.

- Drop-in Express/Koa middleware
- Monitor mode (log only)
- Gradual enforcement rollout
- Compatible with existing auth

Best for: Existing production AI systems

### Selective Components

Use individual Tractatus services à la carte. Mix and match components based on your specific safety requirements.

- Standalone pressure monitoring
- Boundary checks only
- Classification without storage
- Custom component combinations

Best for: Specific safety requirements

## Quick Start Guide

1

### Installation

    npm install @tractatus/framework
    # or
    yarn add @tractatus/framework

Install the framework package and its dependencies (MongoDB for instruction storage).

2

### Initialize Services

    const { TractatusFramework } = require('@tractatus/framework');

    const tractatus = new TractatusFramework({
      mongoUri: process.env.MONGODB_URI,
      verbosity: 'SUMMARY', // or 'VERBOSE', 'SILENT'
      components: {
        classifier: true,
        validator: true,
        boundary: true,
        pressure: true,
        metacognitive: 'selective'
      }
    });

    await tractatus.initialize();

Configure and initialize the framework with your preferred settings.

3

### Classify Instructions

    const instruction = "Always use MongoDB on port 27017";

    const classification = await tractatus.classify(instruction);
    // {
    //   quadrant: 'SYSTEM',
    //   persistence: 'HIGH',
    //   temporal_scope: 'PROJECT',
    //   verification_required: 'MANDATORY',
    //   explicitness: 0.85
    // }

    if (classification.explicitness >= 0.6) {
      await tractatus.store(instruction, classification);
    }

Classify user instructions and store those that meet explicitness threshold.

4

### Validate Actions

    // User instructed: "Check MongoDB at port 27027"
    // But AI about to use port 27017 (pattern recognition bias)

    const action = {
      type: 'db_config',
      parameters: { port: 27017 } // Pattern override!
    };

    const validation = await tractatus.validate(action);

    if (validation.status === 'REJECTED') {
      // "Port 27017 conflicts with instruction: use port 27027"
      console.error(`Validation failed: ${validation.reason}`);
      console.log(`Using instructed port: ${validation.correct_parameters.port}`);
      // Use correct port 27027
    } else {
      executeAction(action);
    }

Validate AI actions against stored instructions before execution.

5

### Enforce Boundaries

    // Check if decision crosses Tractatus boundary
    const decision = {
      domain: 'values',
      description: 'Change privacy policy to enable analytics'
    };

    const boundary = await tractatus.checkBoundary(decision);

    if (!boundary.allowed) {
      // Requires human decision
      await notifyHuman({
        decision,
        reason: boundary.reason,
        alternatives: boundary.ai_can_provide
      });
    }

Enforce boundaries: AI cannot make values decisions without human approval.

## Integration Patterns

### Express Middleware

    app.use(tractatus.middleware({
      mode: 'enforce', // or 'monitor'
      onViolation: async (req, res, violation) => {
        await logViolation(violation);
        res.status(403).json({
          error: 'Tractatus boundary violation',
          reason: violation.reason
        });
      }
    }));

### Content Moderation

    async function moderateContent(content) {
      const decision = {
        domain: 'values',
        action: 'auto_moderate',
        content
      };

      const check = await tractatus.checkBoundary(decision);

      if (!check.allowed) {
        return { action: 'human_review', alternatives: check.ai_can_provide };
      }
    }

### Pressure Monitoring

    const pressure = await tractatus.checkPressure({
      tokens: 150000,
      messages: 45,
      errors: 2
    });

    if (pressure.level === 'CRITICAL') {
      await suggestHandoff(pressure.recommendations);
    } else if (pressure.level === 'HIGH') {
      await increaseVerification();
    }

### Custom Classification

    const customClassifier = {
      patterns: {
        CRITICAL: /security|auth|password/i,
        HIGH: /database|config|api/i
      },

      classify(text) {
        for (const [level, pattern] of Object.entries(this.patterns)) {
          if (pattern.test(text)) return level;
        }
        return 'MEDIUM';
      }
    };

## Implementation Resources

### Technical Documentation

- → Implementation Guide: Python Code
- → Case Studies: Real-World Failures
- → 24-Month Deployment Roadmap
- → Claude Code Enforcement Claude Code

### Examples

- → Classification Demo
- → Boundary Enforcement
- → Real Failure Cases

### Support

Get help with implementation, integration, and troubleshooting.

- • GitHub Issues & Discussions
- • Implementation consulting
- • Community Slack channel

## Ready to Implement?

Join organizations building safer AI systems with architectural guarantees.

View Full Documentation Research Background →