Compositor
The AIPCCompositor orchestrates the full enforcement pipeline. It renders deterministic blocks, validates LLM narrative, enforces compliance, assembles the final response, and produces an audit trail.
The 5-stage pipeline
The Compositor runs five stages in sequence:
- RENDER — Produces deterministic content blocks from validated output using the Renderer.
- VALIDATE — Checks the LLM narrative against contract rules using the Validator.
- ENFORCE — Applies enforcement actions based on violation severity. Critical violations suppress narrative. Major violations trigger redaction or retry.
- ASSEMBLE — Combines deterministic blocks and (possibly modified) narrative into the final response in a fixed compliance order.
- AUDIT — Produces a complete audit trail recording every decision, violation, retry, and enforcement action.
Assembly order
The Compositor assembles the final response in a fixed order. This order is not configurable — it ensures compliance-critical elements always appear in the expected positions:
- Attribution (header position)
- Freshness warning (if applicable)
- Before-data disclosures
- Narrative text (LLM-generated, validated)
- Data blocks (data points and data tables)
- After-data disclosures
- Global footer disclosures
- Suppression notices
- Attribution (footer position)
Retry logic
When the Validator detects major violations, the Compositor can retry the LLM generation with feedback. The retry flow:
- Build a modified prompt that includes the original narrative context plus violation feedback (e.g., "Your previous response contained the prohibited phrase 'guaranteed returns'. Regenerate without it.").
- Call the
retryCallbackwith the modified prompt. - Re-validate the new narrative.
- Repeat up to
maxRetriestimes (default: 2).
If all retries fail, the Compositor falls back to suppressing the narrative and presenting only deterministic blocks.
Output
The Compositor returns a ComplianceEnforcedResponse containing:
| Field | Description |
|---|---|
success | Whether the final response passed compliance checks. |
assembled | The assembled response in multiple formats: plaintext, html, markdown, and structured (array of typed segments). |
audit | Full compliance audit trail: stages executed, violations found, retries attempted, enforcement actions taken, timestamps. |
enforcementLevel | The consumer enforcement level that was applied (L1, L2, or L3). |
narrativeSuppressed | Whether the LLM narrative was suppressed due to critical violations. |
Usage example
import { AIPCCompositor } from '@aipc/runtime';
const response = await AIPCCompositor.enforce({
validatedOutput: result,
narrativeText: llmGeneratedText,
renderConfig: { modality: 'visual', visualFormat: 'html' },
retryCallback: async (modifiedPrompt) => {
return await callLLM(modifiedPrompt);
},
maxRetries: 2
});
if (response.success) {
// Display the assembled response
console.log(response.assembled.html);
// Inspect the audit trail
for (const entry of response.audit.entries) {
console.log(`[${entry.stage}] ${entry.action}: ${entry.detail}`);
}
} else {
// Compliance could not be achieved even after retries
// response.assembled contains only deterministic blocks
console.log(response.assembled.html);
console.warn('Narrative suppressed:', response.audit.suppressionReason);
}