Skip to content

Enterprise API

Multi-tenant scoring isolation, declarative policy rules, and audit logging. These modules are lazy-loaded — importing director_ai does not pull them in until accessed.

from director_ai.enterprise import TenantRouter, Policy, AuditLogger

TenantRouter

Isolates scoring configuration per tenant. Each tenant gets its own CoherenceScorer instance with independent thresholds, knowledge bases, and caching.

from director_ai.enterprise import TenantRouter

router = TenantRouter()
router.register("tenant_a", threshold=0.7, use_nli=True)
router.register("tenant_b", threshold=0.5, use_nli=False)

scorer = router.get_scorer("tenant_a")
approved, score = scorer.review(query, response)

Policy

Declarative rule engine for content filtering. Runs before coherence scoring.

from director_ai.enterprise import Policy

policy = Policy(rules=[
    {"pattern": r"(buy|sell|short)\s+(stock|shares)", "action": "reject"},
    {"pattern": r"\b(SSN|social security)\b", "action": "redact"},
])

result = policy.evaluate(response_text)
if result.rejected:
    print(f"Policy violation: {result.rule}")

AuditLogger

SQLite-backed audit logging for compliance. Records every review decision with full context.

from director_ai.enterprise import AuditLogger

logger = AuditLogger(log_dir="/var/log/director-ai/audit")
logger.log(query, response, score, approved=True)

# Query audit trail
entries = logger.query(tenant_id="tenant_a", since="2026-01-01")

License Matrix

Use Case License Required
Open-source project AGPL-3.0 (free)
Internal tools AGPL-3.0 (free)
SaaS product Commercial license
Proprietary embedding Commercial license

See Licensing for pricing and terms.

Full API

director_ai.core.tenant.TenantRouter

TenantRouter()

Routes requests to tenant-isolated GroundTruthStores.

Thread-safe: stores are created lazily on first access. Supports per-tenant fine-tuned model selection.

get_store

get_store(tenant_id: str) -> GroundTruthStore

Get or create an isolated store for this tenant.

add_fact

add_fact(tenant_id: str, key: str, value: str) -> None

Add a fact to a specific tenant's store.

remove_tenant

remove_tenant(tenant_id: str) -> bool

Remove a tenant and all its data. Returns True if existed.

get_vector_store

get_vector_store(tenant_id: str, backend_type: str = 'memory', **kwargs) -> VectorGroundTruthStore

Get or create a tenant-isolated VectorGroundTruthStore.

Supported backend_type values: "memory", "chroma", "pinecone", "qdrant". Extra kwargs are forwarded to the backend constructor.

set_model

set_model(tenant_id: str, model_id: str, model_path: str, balanced_accuracy: float = 0.0, regression_pp: float = 0.0, recommendation: str = '', dataset_hash: str = '') -> ModelVersion

Register a fine-tuned model for a tenant.

activate_model

activate_model(tenant_id: str, model_id: str) -> bool

Activate a specific model version for a tenant. Deactivates others.

rollback_model

rollback_model(tenant_id: str) -> bool

Deactivate all models for a tenant (revert to baseline).

get_active_model

get_active_model(tenant_id: str) -> ModelVersion | None

Return the active model for a tenant, or None for baseline.

list_models

list_models(tenant_id: str) -> list[ModelVersion]

List all model versions for a tenant.

delete_model

delete_model(tenant_id: str, model_id: str) -> bool

Remove a model version. Cannot delete active models.

get_scorer

get_scorer(tenant_id: str, threshold: float = 0.6, use_nli: bool | None = None) -> CoherenceScorer

Build a CoherenceScorer scoped to this tenant's KB and model.

save_manifest

save_manifest(path: str | Path) -> None

Save all tenant model metadata to a JSON manifest.

load_manifest

load_manifest(path: str | Path) -> int

Load tenant model metadata from a JSON manifest. Returns count loaded.

fact_count

fact_count(tenant_id: str) -> int

Number of facts in a tenant's store.

director_ai.core.safety.audit.AuditLogger

AuditLogger(path: str | Path | None = None, logger_name: str = 'DirectorAI.Audit', hmac_secret: str | None = None)

Structured audit logger with file and logging sinks.

Parameters:

Name Type Description Default
path str | Path | None — JSONL file path. None = logging-only.
None
logger_name str — Python logger name for audit events.
'DirectorAI.Audit'

add_sink

add_sink(sink: Any) -> None

Add an external consumer for audit records (e.g. PostgresAuditSink).

log_review

log_review(query: str, response: str, approved: bool, score: float, h_logical: float = 0.0, h_factual: float = 0.0, policy_violations: list[str] | None = None, tenant_id: str = '', halt_reason: str = '', latency_ms: float = 0.0) -> AuditEntry

Record a review decision.