Extraction Gate
A policy check applied to a proposition after extraction but before it is persisted or projected. A gate inspects a single proposition together with its GateContext and returns a GateEvaluation expressing how the proposition should be routed.
Gates are a standalone, consumer-invoked stage that operates on pipeline output BEFORE the consumer calls save(). They are not embedded in the extraction pipeline itself — the proposition remains the canonical source of truth and gates only route or annotate.
Example usage:
// Run the extraction pipeline as usual.
val results = pipeline.process(chunks, context)
// A simple confidence gate.
val confidenceGate = ExtractionGate { proposition, _ ->
// Use effectiveConfidence() (decay-adjusted), not the raw extraction-time confidence,
// so the gate threshold stays consistent with the query layer.
val decision = if (proposition.effectiveConfidence() < 0.5) {
GateDecision.Reject("confidence below threshold")
} else {
GateDecision.Persist
}
GateEvaluation("ConfidenceGate", proposition, decision)
}
// Evaluate each proposition before persisting, reading the trust score from metadata.
results.propositions.forEach { proposition ->
val gateContext = GateContext(
// Coerce numerically: a wrong-typed value (Float, Int, BigDecimal) would otherwise
// read as null via `as? Double` and the gate would silently fail open.
trustScore = (proposition.metadata["dice.trust.score"] as? Number)?.toDouble(),
)
val evaluation = confidenceGate.evaluate(proposition, gateContext)
when (evaluation.decision) {
is GateDecision.Persist -> repository.save(proposition)
is GateDecision.RouteToReview -> reviewQueue.add(proposition)
is GateDecision.Reject -> { /* drop */}
is GateDecision.SkipProjection -> repository.save(proposition) // persist but do not project
}
}Content copied to clipboard