feat(detection): support provider-native schema enforcement for LLM calls
Goal
Add opt-in provider-native JSON-schema enforcement for detection LLM calls: candidate validation/reclassification and entity augmentation, including all correction/retry paths. Keep existing prompt-and-parser behavior as the default initially.
Follow-up to #305's C4 discussion and schema-tolerance fix (769a5cfd), with compatibility for #267's plain-text augmentation work. This is separate from #304's validation/reclassification semantics and #369's excluded-type prompt instructions.
Motivation and preliminary evidence
Detection currently supplies schema instructions in the prompt and validates responses afterward. The two external augmenter-output models now ignore unknown properties so harmless extras do not alone fail a record. This is useful compatibility behavior, but does not constrain generation itself.
One isolated Gemma/CoreWeave BF16 replay requested native response_format: json_schema with strict mode, closed object schemas, required parameter support and no provider fallback. The request returned in 17.6 seconds and its response passed strict JSON-schema validation. Of 43 suggestions, 41 grounded; two failed non-verbatim-context checks. This single probe demonstrates feasibility for that request only, not universal provider support, guaranteed server enforcement, quality improvement, or complete record recovery. No benchmark inputs/settings were changed and native enforcement was not enabled globally. Raw source text and responses remain private.
Detection-scoped implementation
- Define an explicit supported configuration contract, initially opt-in. Consider
promptandnative_required; introduce a preferred/fallback mode only if its fallback is explicit and observable. Do not silently downgrade required enforcement. - Cover validator pools, validation/reclassification responses, augmentation, parser corrections, semantic retries and grounding-repair calls, on sync and async paths.
- Route schemas through the existing DataDesigner/model-client integration; inspect upstream support first and avoid adding a parallel workflow execution boundary.
- Resolve support per selected model/provider endpoint, including heterogeneous validator pools. Unsupported modes, schema keywords or endpoints must have clear behavior.
- Separate provider-facing decoding schemas from tolerant local response parsers. Close provider-facing objects with
additionalProperties: falsewhere supported, even though external local parsers may ignore extras. Handle optional fields, defaults, enums, references and provider schema subsets deliberately. - Align native-mode prompts with bare structured JSON rather than Markdown code-fence instructions, without changing detection semantics or source text.
- Preserve source grounding, label eligibility/exclusions, request-scoped validator authority, duplicate-alias policy, provenance and final reconciliation. Schema compliance is not semantic correctness.
- Keep refusals, truncation, unsupported-schema/provider errors, transport errors, local parsing errors and grounding failures distinguishable. Retain existing failed-record behavior and avoid exposing raw data in diagnostics.
- Trace requested/effective enforcement mode and any explicitly permitted fallback. Exported configs and remote execution must preserve the selected mode.
Validation / acceptance criteria
- Deterministic mocked request tests inspect actual provider payloads for initial and correction/retry calls, including validator-pool members and sync/async execution.
- Required-mode tests prove there is no silent unconstrained fallback. If preferred mode is implemented, test and trace fallback explicitly.
- Schema tests cover nested extra-property restrictions and optional/required fields; local tests confirm grounding and admission checks still reject semantically invalid outputs.
- Add serialization/export compatibility coverage and documentation for provider limitations and unchanged defaults. Check public API/agent-skill templates if new user-facing knobs are added.
- Run small explicitly approved live probes for claimed supported model/provider combinations, then a pinned paired evaluation of delivery/schema failures, grounding, annotated coverage, latency and tokens before considering a default change. Do not infer population precision from selectively annotated datasets or the one successful probe.
Out of scope
Replacement, rewriting and judge LLM calls; detector endpoint offset handling; changing label/boundary policy; globally enabling enforcement by default; automatically switching models/providers; treating a schema-valid response as semantically correct.