Use prompt-defined structured output contracts
This commit is contained in:
@@ -93,7 +93,7 @@ func testValidationClient(t *testing.T, transport http.RoundTripper) structuredo
|
||||
t.Fatal(err)
|
||||
}
|
||||
settings := loaded.Config.Application.LLM
|
||||
settings.TransientRetries, settings.RepairAttempts = 0, 1
|
||||
settings.TransientRetries = 0
|
||||
client, err := runtime.NewRoleClient("validation", "base", settings, llm.CallHooks{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/config"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/jsonnumber"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/outcomes"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/responseschema"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/stagename"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/structuredoutput"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/prompts"
|
||||
@@ -130,8 +129,8 @@ func (v *LLMBackedValidator) Validate(ctx context.Context, req Request) (Result,
|
||||
coordinates := structuredoutput.DiagnosticContext{StageIndex: req.StageIndex, StageID: req.StageID, Role: "validation", ModuleKey: req.ModuleKey, ModuleInstance: req.ModuleInstance, SectionIndex: req.SectionIndex, BatchIndex: &batch.BatchIndex, ValidatorName: v.name, ProposalIndex: req.RepairProposalIndex, RepairAttempt: req.RepairAttempt}
|
||||
completion, err = req.LLMClient.CompleteStructured(ctx, StructuredCompletionRequest{
|
||||
PromptID: promptMetadata.PromptID,
|
||||
Variables: variables, Schema: responseschema.ValidatorDecisionSetKey,
|
||||
Context: coordinates, CaptureDiagnostics: req.Interactions != nil,
|
||||
Variables: variables,
|
||||
Context: coordinates, CaptureDiagnostics: req.Interactions != nil,
|
||||
}, &response)
|
||||
batchIndex := batch.BatchIndex
|
||||
operation := outcomes.Operation{
|
||||
@@ -153,7 +152,6 @@ func (v *LLMBackedValidator) Validate(ctx context.Context, req Request) (Result,
|
||||
if coordinates.ProposalIndex != nil && req.RepairAttempt != nil {
|
||||
stageInstance = fmt.Sprintf("%s:proposal-%04d:attempt-%04d", stageInstance, *coordinates.ProposalIndex, *req.RepairAttempt)
|
||||
}
|
||||
responseSchema := responseschema.MustLookup(responseschema.ValidatorDecisionSetKey)
|
||||
responsePayload := map[string]any{"decoded": response, "final_content": completion.FinalContent, "model": completion.Model}
|
||||
if reconciled != nil {
|
||||
view := *reconciled
|
||||
@@ -177,7 +175,7 @@ func (v *LLMBackedValidator) Validate(ctx context.Context, req Request) (Result,
|
||||
"stage_index": req.StageIndex, "stage_id": req.StageID, "module_key": req.ModuleKey,
|
||||
"validator_name": v.name, "validator_type": v.validatorType, "batch_index": batch.BatchIndex,
|
||||
"proposal_indices": indices, "repair_proposal_index": coordinates.ProposalIndex, "repair_attempt": req.RepairAttempt,
|
||||
"prompt": completion.Prompt, "response_schema": responseSchema.DiagnosticsMap(),
|
||||
"prompt": completion.Prompt,
|
||||
},
|
||||
RequestPayload: completion.Prepared, ResponsePayload: responsePayload, ErrorPayload: errPayload(callErr),
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/core/schema"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/outcomes"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/proposals"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/responseschema"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/structuredoutput"
|
||||
"gitea.maximumdirect.net/eric/audita/v4/internal/prompts"
|
||||
)
|
||||
@@ -168,7 +167,7 @@ func TestLLMBackedValidatorApprovalAndRejection(t *testing.T) {
|
||||
t.Fatalf("expected one LLM call, got %d", len(client.calls))
|
||||
}
|
||||
call := client.calls[0]
|
||||
if call.Schema != responseschema.ValidatorDecisionSetKey || call.PromptID != prompts.PromptIDValidatorSpokenFormPlausibility || call.Context.Role != "validation" || call.Context.ValidatorName != v.Name() || !strings.Contains(call.Variables["PayloadJSON"], "correction_index") {
|
||||
if call.PromptID != prompts.PromptIDValidatorSpokenFormPlausibility || call.Context.Role != "validation" || call.Context.ValidatorName != v.Name() || !strings.Contains(call.Variables["PayloadJSON"], "correction_index") {
|
||||
t.Fatalf("unexpected validator call: %+v", call)
|
||||
}
|
||||
}
|
||||
@@ -329,7 +328,7 @@ func TestLLMBackedValidatorOversizedSingleProposalRejectsOnlyThatProposal(t *tes
|
||||
}
|
||||
}
|
||||
|
||||
func TestLLMBackedValidatorDiagnosticsIncludeSchemaMetadata(t *testing.T) {
|
||||
func TestLLMBackedValidatorDiagnosticsOmitRegistrySchemaMetadata(t *testing.T) {
|
||||
client := &fakeStructuredLLMClient{responses: []LLMValidationResponse{{Validations: []LLMValidationDecision{
|
||||
{CorrectionIndex: "1", Approved: true, Reason: "ok"},
|
||||
}}}}
|
||||
@@ -349,13 +348,8 @@ func TestLLMBackedValidatorDiagnosticsIncludeSchemaMetadata(t *testing.T) {
|
||||
if !ok {
|
||||
t.Fatalf("expected metadata map, got %T", writer.lastRequestMetadata)
|
||||
}
|
||||
schemaMap, ok := metadata["response_schema"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("expected response_schema map, got %T", metadata["response_schema"])
|
||||
}
|
||||
want := responseschema.MustLookup(responseschema.ValidatorDecisionSetKey)
|
||||
if schemaMap["id"] != want.ID || schemaMap["version"] != want.Version || schemaMap["name"] != want.Name || schemaMap["sha256"] != want.SHA256 {
|
||||
t.Fatalf("unexpected diagnostics schema metadata: got=%v want=%+v", schemaMap, want)
|
||||
if _, exists := metadata["response_schema"]; exists {
|
||||
t.Fatal("unexpected registry schema metadata")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -385,7 +379,7 @@ func TestEveryValidationTypeSelectsEmbeddedPromptAndVariables(t *testing.T) {
|
||||
t.Fatalf("calls=%d", len(client.calls))
|
||||
}
|
||||
call := client.calls[0]
|
||||
if call.PromptID != tc.prompt || call.Schema != responseschema.ValidatorDecisionSetKey || call.Context.Role != "validation" || call.Context.BatchIndex == nil || !strings.Contains(call.Variables["PayloadJSON"], "correction_index") || !strings.Contains(call.Variables["TranscriptDescriptionBlock"], "Fantasy scene") {
|
||||
if call.PromptID != tc.prompt || call.Context.Role != "validation" || call.Context.BatchIndex == nil || !strings.Contains(call.Variables["PayloadJSON"], "correction_index") || !strings.Contains(call.Variables["TranscriptDescriptionBlock"], "Fantasy scene") {
|
||||
t.Fatalf("mapping: %+v", call)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user