@flow-state-dev/patterns/response-auditor
Interfaces
ResponseAuditorConfig
Properties
alwaysRun?
alwaysRun?: boolean;
Run even if no analyzers exceed threshold (default true).
analyzers
analyzers: BlockDefinition<any, any, any, any>[];
Pluggable analyzer blocks. Each receives { userInput, response } and returns AnalyzerResult.
displayMode?
displayMode?: DisplayMode;
How to render annotations in UI.
maxConcurrency?
maxConcurrency?: number;
Parallel analyzer limit (default: all).
threshold?
threshold?: number;
Global threshold (default 0.3) — only surface results above this score.
Type Aliases
AnalyzerResult
type AnalyzerResult = z.infer<typeof AnalyzerResultSchema>;
AuditAnnotation
type AuditAnnotation = z.infer<typeof AuditAnnotationSchema>;
AuditorInput
type AuditorInput = z.infer<typeof auditorInputSchema>;
DisplayMode
type DisplayMode = "inline" | "message";
ResponseAuditorState
type ResponseAuditorState = z.infer<typeof responseAuditorStateSchema>;
Variables
aggregateResults
const aggregateResults: BlockDefinition;
Collects analyzer results and computes an overall score (average of all analyzer scores).
AnalyzerResultSchema
const AnalyzerResultSchema: z.ZodObject<{
analyzerId: z.ZodString;
annotations: z.ZodArray<z.ZodObject<{
description: z.ZodString;
evidence: z.ZodOptional<z.ZodString>;
label: z.ZodString;
severity: z.ZodEnum<["info", "warning", "critical"]>;
type: z.ZodString;
}, "strip", z.ZodTypeAny, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}>, "many">;
category: z.ZodString;
score: z.ZodNumber;
shouldSurface: z.ZodBoolean;
supplementary: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, "strip", z.ZodTypeAny, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}>;
AuditAnnotationSchema
const AuditAnnotationSchema: z.ZodObject<{
description: z.ZodString;
evidence: z.ZodOptional<z.ZodString>;
label: z.ZodString;
severity: z.ZodEnum<["info", "warning", "critical"]>;
type: z.ZodString;
}, "strip", z.ZodTypeAny, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}>;
auditorInputSchema
const auditorInputSchema: z.ZodObject<{
response: z.ZodString;
userInput: z.ZodString;
}, "strip", z.ZodTypeAny, {
response: string;
userInput: string;
}, {
response: string;
userInput: string;
}>;
captureContext
const captureContext: BlockDefinition;
Extracts userInput and response from the .sideChain() input.
When the auditor is composed via .sideChain(), it receives the preceding step's
output. The auditor expects { userInput, response } — the connector on
.sideChain() should map the pipeline value to this shape.
Stores the captured context in sequencer state for downstream blocks.
Wired as .tap() — state-only, no echoed output.
Remarks
Compose this with .tap(captureContext), never .step(captureContext).
It returns nothing, so as a .step() it hands undefined to the next step.
responseAuditorStateSchema
const responseAuditorStateSchema: z.ZodObject<{
overallScore: z.ZodDefault<z.ZodNumber>;
response: z.ZodDefault<z.ZodString>;
results: z.ZodDefault<z.ZodArray<z.ZodObject<{
analyzerId: z.ZodString;
annotations: z.ZodArray<z.ZodObject<{
description: z.ZodString;
evidence: z.ZodOptional<z.ZodString>;
label: z.ZodString;
severity: z.ZodEnum<[..., ..., ...]>;
type: z.ZodString;
}, "strip", z.ZodTypeAny, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}>, "many">;
category: z.ZodString;
score: z.ZodNumber;
shouldSurface: z.ZodBoolean;
supplementary: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, "strip", z.ZodTypeAny, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}>, "many">>;
surfacedResults: z.ZodDefault<z.ZodArray<z.ZodObject<{
analyzerId: z.ZodString;
annotations: z.ZodArray<z.ZodObject<{
description: z.ZodString;
evidence: z.ZodOptional<z.ZodString>;
label: z.ZodString;
severity: z.ZodEnum<[..., ..., ...]>;
type: z.ZodString;
}, "strip", z.ZodTypeAny, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}>, "many">;
category: z.ZodString;
score: z.ZodNumber;
shouldSurface: z.ZodBoolean;
supplementary: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
}, "strip", z.ZodTypeAny, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}>, "many">>;
userInput: z.ZodDefault<z.ZodString>;
}, "strip", z.ZodTypeAny, {
overallScore: number;
response: string;
results: object[];
surfacedResults: object[];
userInput: string;
}, {
overallScore?: number;
response?: string;
results?: object[];
surfacedResults?: object[];
userInput?: string;
}>;
Functions
applyThreshold()
function applyThreshold(threshold): BlockDefinition<ZodObject<{
overallScore: ZodNumber;
results: ZodArray<ZodObject<{
analyzerId: ZodString;
annotations: ZodArray<ZodObject<{
description: ZodString;
evidence: ZodOptional<ZodString>;
label: ZodString;
severity: ZodEnum<[..., ..., ...]>;
type: ZodString;
}, "strip", ZodTypeAny, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}>, "many">;
category: ZodString;
score: ZodNumber;
shouldSurface: ZodBoolean;
supplementary: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
}, "strip", ZodTypeAny, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}>, "many">;
}, "strip", ZodTypeAny, {
overallScore: number;
results: object[];
}, {
overallScore: number;
results: object[];
}>, ZodObject<object & object, "strip", ZodTypeAny, {
overallScore: number;
results: object[];
surfacedResults: object[];
}, {
overallScore: number;
results: object[];
surfacedResults: object[];
}>, {
overallScore: number;
results: object[];
}, {
overallScore: number;
results: object[];
surfacedResults: object[];
}>;
Filters analyzer results to only those above the configured threshold.
Results where shouldSurface is true OR score exceeds the threshold are kept.
Parameters
threshold
number
Returns
BlockDefinition<ZodObject<{
overallScore: ZodNumber;
results: ZodArray<ZodObject<{
analyzerId: ZodString;
annotations: ZodArray<ZodObject<{
description: ZodString;
evidence: ZodOptional<ZodString>;
label: ZodString;
severity: ZodEnum<[..., ..., ...]>;
type: ZodString;
}, "strip", ZodTypeAny, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}, {
description: string;
evidence?: string;
label: string;
severity: "critical" | "info" | "warning";
type: string;
}>, "many">;
category: ZodString;
score: ZodNumber;
shouldSurface: ZodBoolean;
supplementary: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
}, "strip", ZodTypeAny, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}>, "many">;
}, "strip", ZodTypeAny, {
overallScore: number;
results: object[];
}, {
overallScore: number;
results: object[];
}>, ZodObject<object & object, "strip", ZodTypeAny, {
overallScore: number;
results: object[];
surfacedResults: object[];
}, {
overallScore: number;
results: object[];
surfacedResults: object[];
}>, {
overallScore: number;
results: object[];
}, {
overallScore: number;
results: object[];
surfacedResults: object[];
}>
responseAuditor()
function responseAuditor(config): SequencerDefinition<{
response: string;
userInput: string;
}, {
overallScore: number;
results: object[];
surfacedResults: object[];
}, ZodObject<{
overallScore: ZodDefault<ZodNumber>;
response: ZodDefault<ZodString>;
results: ZodDefault<ZodArray<ZodObject<{
analyzerId: ZodString;
annotations: ZodArray<ZodObject<{
description: ZodString;
evidence: ZodOptional<...>;
label: ZodString;
severity: ZodEnum<...>;
type: ZodString;
}, "strip", ZodTypeAny, {
description: string;
evidence?: ... | ...;
label: string;
severity: ... | ... | ...;
type: string;
}, {
description: string;
evidence?: ... | ...;
label: string;
severity: ... | ... | ...;
type: string;
}>, "many">;
category: ZodString;
score: ZodNumber;
shouldSurface: ZodBoolean;
supplementary: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
}, "strip", ZodTypeAny, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}>, "many">>;
surfacedResults: ZodDefault<ZodArray<ZodObject<{
analyzerId: ZodString;
annotations: ZodArray<ZodObject<{
description: ZodString;
evidence: ZodOptional<...>;
label: ZodString;
severity: ZodEnum<...>;
type: ZodString;
}, "strip", ZodTypeAny, {
description: string;
evidence?: ... | ...;
label: string;
severity: ... | ... | ...;
type: string;
}, {
description: string;
evidence?: ... | ...;
label: string;
severity: ... | ... | ...;
type: string;
}>, "many">;
category: ZodString;
score: ZodNumber;
shouldSurface: ZodBoolean;
supplementary: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
}, "strip", ZodTypeAny, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}>, "many">>;
userInput: ZodDefault<ZodString>;
}, "strip", ZodTypeAny, {
overallScore: number;
response: string;
results: object[];
surfacedResults: object[];
userInput: string;
}, {
overallScore?: number;
response?: string;
results?: object[];
surfacedResults?: object[];
userInput?: string;
}>, undefined>;
Creates a response auditor sequencer — a .sideChain()-compatible block that
runs pluggable analyzers against a completed AI response and produces
structured annotations.
mainSequencer
.step(primaryGenerator)
.sideChain(
(output) => ({ userInput: output.userInput, response: output.text }),
responseAuditor({
analyzers: [biasAnalyzer, toneAnalyzer],
threshold: 0.3,
displayMode: 'inline',
})
)
Parameters
config
Returns
SequencerDefinition<{
response: string;
userInput: string;
}, {
overallScore: number;
results: object[];
surfacedResults: object[];
}, ZodObject<{
overallScore: ZodDefault<ZodNumber>;
response: ZodDefault<ZodString>;
results: ZodDefault<ZodArray<ZodObject<{
analyzerId: ZodString;
annotations: ZodArray<ZodObject<{
description: ZodString;
evidence: ZodOptional<...>;
label: ZodString;
severity: ZodEnum<...>;
type: ZodString;
}, "strip", ZodTypeAny, {
description: string;
evidence?: ... | ...;
label: string;
severity: ... | ... | ...;
type: string;
}, {
description: string;
evidence?: ... | ...;
label: string;
severity: ... | ... | ...;
type: string;
}>, "many">;
category: ZodString;
score: ZodNumber;
shouldSurface: ZodBoolean;
supplementary: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
}, "strip", ZodTypeAny, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}>, "many">>;
surfacedResults: ZodDefault<ZodArray<ZodObject<{
analyzerId: ZodString;
annotations: ZodArray<ZodObject<{
description: ZodString;
evidence: ZodOptional<...>;
label: ZodString;
severity: ZodEnum<...>;
type: ZodString;
}, "strip", ZodTypeAny, {
description: string;
evidence?: ... | ...;
label: string;
severity: ... | ... | ...;
type: string;
}, {
description: string;
evidence?: ... | ...;
label: string;
severity: ... | ... | ...;
type: string;
}>, "many">;
category: ZodString;
score: ZodNumber;
shouldSurface: ZodBoolean;
supplementary: ZodOptional<ZodRecord<ZodString, ZodUnknown>>;
}, "strip", ZodTypeAny, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}, {
analyzerId: string;
annotations: object[];
category: string;
score: number;
shouldSurface: boolean;
supplementary?: Record<string, unknown>;
}>, "many">>;
userInput: ZodDefault<ZodString>;
}, "strip", ZodTypeAny, {
overallScore: number;
response: string;
results: object[];
surfacedResults: object[];
userInput: string;
}, {
overallScore?: number;
response?: string;
results?: object[];
surfacedResults?: object[];
userInput?: string;
}>, undefined>