Migrate NPC and location normalization to native correction and explicit fallback handling

This commit is contained in:
2026-11-22 00:27:34 +00:00
parent 772b8619c1
commit 4f82d01534
16 changed files with 1062 additions and 732 deletions

View File

@@ -11,9 +11,9 @@ prompts:
messages:
- role: system
content_file: ../../../shared/prompts/common-dnd-system.md
- role: user
- role: system
content_file: ../../../../generic/normalize/deduplication/prompts/protocol.md
- role: user
- role: system
content_file: ./instructions.md
cache_control:
type: ephemeral
@@ -27,3 +27,17 @@ prompts:
format: json
validation_mode: json_schema
schema_path: generic/normalize/deduplication/schemas/semantic_reconciliation_llm.v1.json
- id: dnd.location_registry.normalize.repair
default_profile: notarius/dnd-extraction
inputs:
- name: guidance
required: true
content_type: text/plain
messages:
- role: user
content_file: ../../../../generic/normalize/deduplication/prompts/correction.md
output:
format: json
validation_mode: json_schema
schema_path: generic/normalize/deduplication/schemas/semantic_reconciliation_llm.v1.json

View File

@@ -11,9 +11,9 @@ prompts:
messages:
- role: system
content_file: ../../../shared/prompts/common-dnd-system.md
- role: user
- role: system
content_file: ../../../../generic/normalize/deduplication/prompts/protocol.md
- role: user
- role: system
content_file: ./instructions.md
cache_control:
type: ephemeral
@@ -27,3 +27,17 @@ prompts:
format: json
validation_mode: json_schema
schema_path: generic/normalize/deduplication/schemas/semantic_reconciliation_llm.v1.json
- id: dnd.npc_registry.normalize.repair
default_profile: notarius/dnd-extraction
inputs:
- name: guidance
required: true
content_type: text/plain
messages:
- role: user
content_file: ../../../../generic/normalize/deduplication/prompts/correction.md
output:
format: json
validation_mode: json_schema
schema_path: generic/normalize/deduplication/schemas/semantic_reconciliation_llm.v1.json

View File

@@ -146,6 +146,58 @@ func TestEmbeddedPromptsPrepareWithNativeContracts(t *testing.T) {
}
}
func TestRegistryNormalizationPromptPairsRetainTheirNativeContracts(t *testing.T) {
_, engine := loadNativeAssets(t)
for _, test := range []struct {
id string
guidance string
rules []string
}{
{"notarius/dnd.npc_registry.normalize", "Preserve distinct individuals.", []string{"same individual", "unadorned proper name"}},
{"notarius/dnd.location_registry.normalize", "Keep parent and child places separate.", []string{"same physical place", "parent and child places"}},
} {
t.Run(test.id, func(t *testing.T) {
initial, err := engine.PrepareExecution(context.Background(), promptkit.RunRequest{
PromptID: test.id, APIKey: "test-only", Inputs: map[string]promptkit.ArtifactRef{
"candidates": promptkit.Inline(`{"candidate_number_range":{"first":1,"last":2},"candidates":[]}`),
"transcript": promptkit.Inline(`{"windows":[]}`),
},
})
if err != nil {
t.Fatal(err)
}
defer initial.Discard()
correction, err := engine.PrepareExecution(context.Background(), promptkit.RunRequest{
PromptID: test.id + ".repair", APIKey: "test-only",
Inputs: map[string]promptkit.ArtifactRef{"guidance": promptkit.Inline(test.guidance)},
})
if err != nil {
t.Fatal(err)
}
defer correction.Discard()
first, next := initial.Details(), correction.Details()
if first.SelectedProfileID != "notarius/dnd-extraction" || next.SelectedProfileID != first.SelectedProfileID ||
first.StructuredOutput == nil || next.StructuredOutput == nil || !reflect.DeepEqual(first.OutputContract, next.OutputContract) {
t.Fatal("normalization pair lost its shared native defaults/output contract")
}
var system string
for _, message := range first.Messages {
if message.Role == "system" {
system += message.Content
}
}
for _, rule := range append(test.rules, "candidate_number_range", "start_unit_id", "canonical_candidate_number") {
if !strings.Contains(system, rule) {
t.Fatalf("missing enduring system principle %q", rule)
}
}
if len(next.Messages) != 1 || next.Messages[0].Role != "user" || !strings.Contains(next.Messages[0].Content, test.guidance) {
t.Fatal("correction did not supply only the findings and replacement assignment")
}
})
}
}
func TestEmbeddedProfileRetainsSelectedExecutionDefaults(t *testing.T) {
t.Parallel()
_, engine := loadNativeAssets(t)