Propagate structured repair requests

This commit is contained in:
2026-08-25 19:39:04 +00:00
parent ab9b743df6
commit e00cc45c6b
12 changed files with 154 additions and 134 deletions

View File

@@ -427,7 +427,7 @@ git diff --check
match the target semantics. match the target semantics.
- No PromptKit type crosses the LLM package boundary. - No PromptKit type crosses the LLM package boundary.
## Stage 6: Propagate Repair Policy Through Framework Requests ## Stage 6: Propagate Repair Policy Through Framework Requests
### Goal ### Goal

View File

@@ -140,6 +140,7 @@ type ParseRequest struct {
Path string `json:"path,omitempty"` Path string `json:"path,omitempty"`
Raw []byte `json:"-"` Raw []byte `json:"-"`
LLMProfile string `json:"llm_profile,omitempty"` LLMProfile string `json:"llm_profile,omitempty"`
StructuredOutputRepairAttempts *int `json:"structured_output_repair_attempts,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"` Metadata map[string]any `json:"metadata,omitempty"`
} }
@@ -154,6 +155,7 @@ type ChunkRequest struct {
SessionID string `json:"session_id,omitempty"` SessionID string `json:"session_id,omitempty"`
References ReferenceSet `json:"references,omitempty"` References ReferenceSet `json:"references,omitempty"`
LLMProfile string `json:"llm_profile,omitempty"` LLMProfile string `json:"llm_profile,omitempty"`
StructuredOutputRepairAttempts *int `json:"structured_output_repair_attempts,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"` Metadata map[string]any `json:"metadata,omitempty"`
} }
@@ -297,6 +299,7 @@ type OutputRequest struct {
Rejected []RejectedOutput `json:"rejected,omitempty"` Rejected []RejectedOutput `json:"rejected,omitempty"`
Warnings []Warning `json:"warnings,omitempty"` Warnings []Warning `json:"warnings,omitempty"`
LLMProfile string `json:"llm_profile,omitempty"` LLMProfile string `json:"llm_profile,omitempty"`
StructuredOutputRepairAttempts *int `json:"structured_output_repair_attempts,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"` Metadata map[string]any `json:"metadata,omitempty"`
ChunkMap *SerializedArtifact `json:"chunk_map,omitempty"` ChunkMap *SerializedArtifact `json:"chunk_map,omitempty"`
EvidenceContext *SerializedArtifact `json:"evidence_context,omitempty"` EvidenceContext *SerializedArtifact `json:"evidence_context,omitempty"`

View File

@@ -41,6 +41,7 @@ type TypedExtractionRequest struct {
SessionID string SessionID string
References ReferenceSet References ReferenceSet
LLMProfile string LLMProfile string
StructuredOutputRepairAttempts *int
Metadata map[string]any Metadata map[string]any
} }
@@ -63,6 +64,7 @@ type TypedMergeRequest[T any] struct {
SessionID string SessionID string
References ReferenceSet References ReferenceSet
LLMProfile string LLMProfile string
StructuredOutputRepairAttempts *int
Metadata map[string]any Metadata map[string]any
} }
@@ -84,6 +86,7 @@ type TypedNormalizeRequest[T any] struct {
SessionID string SessionID string
References ReferenceSet References ReferenceSet
LLMProfile string LLMProfile string
StructuredOutputRepairAttempts *int
Metadata map[string]any Metadata map[string]any
} }
@@ -124,6 +127,7 @@ type TypedValidationRequest[T any] struct {
SessionID string SessionID string
References ReferenceSet References ReferenceSet
LLMProfile string LLMProfile string
StructuredOutputRepairAttempts *int
Metadata map[string]any Metadata map[string]any
Chunk *source.Chunk Chunk *source.Chunk
Chunks []source.Chunk Chunks []source.Chunk
@@ -145,6 +149,7 @@ type ChunkValidationRequest struct {
SessionID string SessionID string
References ReferenceSet References ReferenceSet
LLMProfile string LLMProfile string
StructuredOutputRepairAttempts *int
Metadata map[string]any Metadata map[string]any
Chunks []source.Chunk Chunks []source.Chunk
} }
@@ -165,6 +170,7 @@ type SerializedValidationRequest struct {
SessionID string SessionID string
References ReferenceSet References ReferenceSet
LLMProfile string LLMProfile string
StructuredOutputRepairAttempts *int
Metadata map[string]any Metadata map[string]any
Chunk *source.Chunk Chunk *source.Chunk
Chunks []source.Chunk Chunks []source.Chunk

View File

@@ -23,6 +23,7 @@ const (
type ModuleBinding struct { type ModuleBinding struct {
Module string `json:"module"` Module string `json:"module"`
LLMProfile string `json:"llm_profile,omitempty"` LLMProfile string `json:"llm_profile,omitempty"`
StructuredOutputRepairAttempts *int `json:"structured_output_repair_attempts,omitempty"`
Retries int `json:"retries,omitempty"` Retries int `json:"retries,omitempty"`
Options map[string]any `json:"options,omitempty"` Options map[string]any `json:"options,omitempty"`
References map[string]ReferenceSource `json:"references,omitempty"` References map[string]ReferenceSource `json:"references,omitempty"`

View File

@@ -177,6 +177,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
Path: input.Path, Path: input.Path,
Raw: input.RawInput, Raw: input.RawInput,
LLMProfile: input.pipeline.Input.LLMProfile, LLMProfile: input.pipeline.Input.LLMProfile,
StructuredOutputRepairAttempts: input.pipeline.Input.StructuredOutputRepairAttempts,
Metadata: requestMetadata, Metadata: requestMetadata,
}) })
if ctxErr := ctx.Err(); ctxErr != nil { if ctxErr := ctx.Err(); ctxErr != nil {
@@ -365,6 +366,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
Rejected: cloneRejectedOutputs(output.Rejected), Rejected: cloneRejectedOutputs(output.Rejected),
Warnings: output.Warnings, Warnings: output.Warnings,
LLMProfile: input.pipeline.Output.LLMProfile, LLMProfile: input.pipeline.Output.LLMProfile,
StructuredOutputRepairAttempts: input.pipeline.Output.StructuredOutputRepairAttempts,
Metadata: outputMetadata, Metadata: outputMetadata,
ChunkMap: contracts.CloneSerializedArtifactPointer(acceptedChunkMap), ChunkMap: contracts.CloneSerializedArtifactPointer(acceptedChunkMap),
EvidenceContext: contracts.CloneSerializedArtifactPointer(evidenceArtifact), EvidenceContext: contracts.CloneSerializedArtifactPointer(evidenceArtifact),

View File

@@ -96,7 +96,7 @@ func (r *Runner) runChunkPlan(ctx context.Context, input RunInput, doc *source.S
chunkResult, callErr := chunker.Plan(attemptCtx, contracts.ChunkRequest{ chunkResult, callErr := chunker.Plan(attemptCtx, contracts.ChunkRequest{
Source: doc, SourceInput: sourceInput.Clone(), SessionID: sessionID, Source: doc, SourceInput: sourceInput.Clone(), SessionID: sessionID,
References: CloneReferenceSet(input.pipeline.ChunkReferences.ReferenceSet), References: CloneReferenceSet(input.pipeline.ChunkReferences.ReferenceSet),
LLMProfile: input.pipeline.Chunk.LLMProfile, Metadata: requestMetadata, LLMProfile: input.pipeline.Chunk.LLMProfile, StructuredOutputRepairAttempts: input.pipeline.Chunk.StructuredOutputRepairAttempts, Metadata: requestMetadata,
}) })
if callErr != nil { if callErr != nil {
return retryAttemptResult{}, terminal.record(nil, fmt.Errorf("chunk source with chunker %q: %w", chunker.Key(), callErr)) return retryAttemptResult{}, terminal.record(nil, fmt.Errorf("chunk source with chunker %q: %w", chunker.Key(), callErr))

View File

@@ -420,7 +420,7 @@ func (r *Runner) runExtractJob(ctx context.Context, input RunInput, doc *source.
return retryAttemptResult{}, terminal.record(nil, fmt.Errorf("clone extract request metadata: %w", metadataErr)) return retryAttemptResult{}, terminal.record(nil, fmt.Errorf("clone extract request metadata: %w", metadataErr))
} }
extractReferences := operationReferenceSet(input, lane.ExtractReferences) extractReferences := operationReferenceSet(input, lane.ExtractReferences)
extracted, callErr := typed.extract(attemptCtx, typed.extractor, contracts.TypedExtractionRequest{Source: doc, Chunk: &chunk, SourceInput: chunkInputMaterial(sourceInput, chunk), SessionID: sessionID, References: CloneReferenceSet(extractReferences), LLMProfile: lane.Extract.LLMProfile, Metadata: requestMetadata}) extracted, callErr := typed.extract(attemptCtx, typed.extractor, contracts.TypedExtractionRequest{Source: doc, Chunk: &chunk, SourceInput: chunkInputMaterial(sourceInput, chunk), SessionID: sessionID, References: CloneReferenceSet(extractReferences), LLMProfile: lane.Extract.LLMProfile, StructuredOutputRepairAttempts: lane.Extract.StructuredOutputRepairAttempts, Metadata: requestMetadata})
if callErr != nil { if callErr != nil {
attemptErr := fmt.Errorf("extract lane %q chunk %q with extractor %q: %w", lane.ID, chunk.ID, lane.Extract.Module, callErr) attemptErr := fmt.Errorf("extract lane %q chunk %q with extractor %q: %w", lane.ID, chunk.ID, lane.Extract.Module, callErr)
return retryAttemptResult{}, terminal.record(nil, attemptErr) return retryAttemptResult{}, terminal.record(nil, attemptErr)

View File

@@ -258,7 +258,7 @@ func (r *Runner) runMergeStage(ctx context.Context, input RunInput, checkpoints
if metadataErr != nil { if metadataErr != nil {
return retryAttemptResult{}, terminal.record(nil, fmt.Errorf("clone merge request metadata: %w", metadataErr)) return retryAttemptResult{}, terminal.record(nil, fmt.Errorf("clone merge request metadata: %w", metadataErr))
} }
result, callErr := typed.merge(attemptCtx, typed.merger, contracts.TypedMergeRequest[any]{Source: doc, LaneID: lane.ID, ExtractOutputs: mergeInputs, SourceInput: sourceInput.Clone(), SessionID: sessionID, References: CloneReferenceSet(mergeReferences), LLMProfile: lane.Merge.LLMProfile, Metadata: requestMetadata}) result, callErr := typed.merge(attemptCtx, typed.merger, contracts.TypedMergeRequest[any]{Source: doc, LaneID: lane.ID, ExtractOutputs: mergeInputs, SourceInput: sourceInput.Clone(), SessionID: sessionID, References: CloneReferenceSet(mergeReferences), LLMProfile: lane.Merge.LLMProfile, StructuredOutputRepairAttempts: lane.Merge.StructuredOutputRepairAttempts, Metadata: requestMetadata})
if callErr != nil { if callErr != nil {
attemptErr := fmt.Errorf("merge lane %q with merger %q: %w", lane.ID, lane.Merge.Module, callErr) attemptErr := fmt.Errorf("merge lane %q with merger %q: %w", lane.ID, lane.Merge.Module, callErr)
return retryAttemptResult{}, terminal.record(nil, attemptErr) return retryAttemptResult{}, terminal.record(nil, attemptErr)
@@ -360,7 +360,7 @@ func (r *Runner) runNormalizeStage(ctx context.Context, input RunInput, checkpoi
if metadataErr != nil { if metadataErr != nil {
return retryAttemptResult{}, terminal.record(nil, fmt.Errorf("clone normalize request metadata: %w", metadataErr)) return retryAttemptResult{}, terminal.record(nil, fmt.Errorf("clone normalize request metadata: %w", metadataErr))
} }
result, callErr := typed.normalize(attemptCtx, typed.normalizer, contracts.TypedNormalizeRequest[any]{Source: doc, LaneID: lane.ID, MergeOutput: contracts.MergeArtifact[any]{LaneID: lane.ID, MergerKey: lane.Merge.Module, SourceID: doc.ID, Value: merged.Value}, SourceInput: sourceInput.Clone(), SessionID: sessionID, References: CloneReferenceSet(normalizeReferences), LLMProfile: lane.Normalize.LLMProfile, Metadata: requestMetadata}) result, callErr := typed.normalize(attemptCtx, typed.normalizer, contracts.TypedNormalizeRequest[any]{Source: doc, LaneID: lane.ID, MergeOutput: contracts.MergeArtifact[any]{LaneID: lane.ID, MergerKey: lane.Merge.Module, SourceID: doc.ID, Value: merged.Value}, SourceInput: sourceInput.Clone(), SessionID: sessionID, References: CloneReferenceSet(normalizeReferences), LLMProfile: lane.Normalize.LLMProfile, StructuredOutputRepairAttempts: lane.Normalize.StructuredOutputRepairAttempts, Metadata: requestMetadata})
if callErr != nil { if callErr != nil {
attemptErr := fmt.Errorf("normalize lane %q with normalizer %q: %w", lane.ID, lane.Normalize.Module, callErr) attemptErr := fmt.Errorf("normalize lane %q with normalizer %q: %w", lane.ID, lane.Normalize.Module, callErr)
return retryAttemptResult{}, terminal.record(nil, attemptErr) return retryAttemptResult{}, terminal.record(nil, attemptErr)
@@ -511,6 +511,7 @@ func (r *Runner) validateTypedArtifact(ctx context.Context, codec artifactCodecE
} }
requestTarget.value = candidateValue requestTarget.value = candidateValue
requestTarget.llmProfile = binding.LLMProfile requestTarget.llmProfile = binding.LLMProfile
requestTarget.structuredOutputRepairAttempts = binding.StructuredOutputRepairAttempts
result, err = item.typedValidate(validatorCtx, item.typed, requestTarget) result, err = item.typedValidate(validatorCtx, item.typed, requestTarget)
case ValidatorTargetSerialized: case ValidatorTargetSerialized:
artifact, encodeErr := validationCandidateArtifact(codec, target) artifact, encodeErr := validationCandidateArtifact(codec, target)
@@ -518,7 +519,7 @@ func (r *Runner) validateTypedArtifact(ctx context.Context, codec artifactCodecE
err = encodeErr err = encodeErr
break break
} }
result, err = item.serialized.Validate(validatorCtx, contracts.SerializedValidationRequest{Stage: string(target.stage), LaneID: target.laneID, ModuleKey: target.moduleKey, Source: target.source, SourceID: target.sourceID, SourceInput: requestTarget.sourceInput, SessionID: target.sessionID, References: requestTarget.references, LLMProfile: binding.LLMProfile, Metadata: requestTarget.metadata, Chunk: requestTarget.chunk, Chunks: requestTarget.chunks, Schema: contracts.CloneArtifactSchema(artifact.Artifact.Schema), MediaType: artifact.Artifact.MediaType, Content: append([]byte(nil), artifact.Artifact.Content...)}) result, err = item.serialized.Validate(validatorCtx, contracts.SerializedValidationRequest{Stage: string(target.stage), LaneID: target.laneID, ModuleKey: target.moduleKey, Source: target.source, SourceID: target.sourceID, SourceInput: requestTarget.sourceInput, SessionID: target.sessionID, References: requestTarget.references, LLMProfile: binding.LLMProfile, StructuredOutputRepairAttempts: binding.StructuredOutputRepairAttempts, Metadata: requestTarget.metadata, Chunk: requestTarget.chunk, Chunks: requestTarget.chunks, Schema: contracts.CloneArtifactSchema(artifact.Artifact.Schema), MediaType: artifact.Artifact.MediaType, Content: append([]byte(nil), artifact.Artifact.Content...)})
default: default:
return nil, nil, fmt.Errorf("validator %q is incompatible with typed artifact validation", binding.Module) return nil, nil, fmt.Errorf("validator %q is incompatible with typed artifact validation", binding.Module)
} }

View File

@@ -38,6 +38,7 @@ type typedValidationTarget struct {
sessionID string sessionID string
references contracts.ReferenceSet references contracts.ReferenceSet
llmProfile string llmProfile string
structuredOutputRepairAttempts *int
metadata map[string]any metadata map[string]any
chunk *source.Chunk chunk *source.Chunk
chunks []source.Chunk chunks []source.Chunk

View File

@@ -94,6 +94,10 @@ func cloneModuleBindings(bindings []ModuleBinding) []ModuleBinding {
func cloneModuleBinding(binding ModuleBinding) ModuleBinding { func cloneModuleBinding(binding ModuleBinding) ModuleBinding {
binding.Module = strings.TrimSpace(binding.Module) binding.Module = strings.TrimSpace(binding.Module)
binding.LLMProfile = strings.TrimSpace(binding.LLMProfile) binding.LLMProfile = strings.TrimSpace(binding.LLMProfile)
if binding.StructuredOutputRepairAttempts != nil {
value := *binding.StructuredOutputRepairAttempts
binding.StructuredOutputRepairAttempts = &value
}
binding.Options = cloneOptions(binding.Options) binding.Options = cloneOptions(binding.Options)
if len(binding.References) > 0 { if len(binding.References) > 0 {
references := make(map[string]ReferenceSource, len(binding.References)) references := make(map[string]ReferenceSource, len(binding.References))

View File

@@ -115,7 +115,7 @@ func RegisterTypedValidatorBuilder[T any](registry *ValidatorRegistry, kind cont
if err != nil { if err != nil {
return contracts.ValidationResult{}, err return contracts.ValidationResult{}, err
} }
return validator.Validate(ctx, contracts.TypedValidationRequest[T]{Stage: string(target.stage), LaneID: target.laneID, ModuleKey: target.moduleKey, Source: target.source, SourceID: target.sourceID, SourceInput: target.sourceInput, SessionID: target.sessionID, References: target.references, LLMProfile: target.llmProfile, Metadata: target.metadata, Chunk: target.chunk, Chunks: target.chunks, Ref: target.ref, Value: value}) return validator.Validate(ctx, contracts.TypedValidationRequest[T]{Stage: string(target.stage), LaneID: target.laneID, ModuleKey: target.moduleKey, Source: target.source, SourceID: target.sourceID, SourceInput: target.sourceInput, SessionID: target.sessionID, References: target.references, LLMProfile: target.llmProfile, StructuredOutputRepairAttempts: target.structuredOutputRepairAttempts, Metadata: target.metadata, Chunk: target.chunk, Chunks: target.chunks, Ref: target.ref, Value: value})
}, },
} }
return nil return nil

View File

@@ -47,6 +47,7 @@ type Request struct {
Source *source.SourceDocument Source *source.SourceDocument
Candidates []Candidate Candidates []Candidate
ProfileID string ProfileID string
StructuredOutputRepairAttempts *int
SessionID string SessionID string
} }
@@ -168,6 +169,7 @@ func (engine *Engine) Reconcile(ctx context.Context, request Request) (Result, e
PromptVersion: engine.prompt.Version, PromptVersion: engine.prompt.Version,
ProfileID: request.ProfileID, ProfileID: request.ProfileID,
SessionID: request.SessionID, SessionID: request.SessionID,
StructuredOutputRepairAttempts: request.StructuredOutputRepairAttempts,
Inputs: preparation.Materials(), Inputs: preparation.Materials(),
}, &response) }, &response)
if err != nil { if err != nil {