Clarify prompt boundaries and enforce repair decisions
This commit is contained in:
@@ -9,9 +9,14 @@ import (
|
||||
|
||||
// RepairResponse is one model response for an original proposal reference.
|
||||
type RepairResponse struct {
|
||||
ProposalRef int `json:"proposal_ref"`
|
||||
Action string `json:"action"`
|
||||
Correction *StructuredCorrectionProposal `json:"correction"`
|
||||
ProposalRef int `json:"proposal_ref"`
|
||||
Decision RepairDecision `json:"decision"`
|
||||
}
|
||||
|
||||
// RepairDecision selects revision or withdrawal for the referenced proposal.
|
||||
type RepairDecision struct {
|
||||
Action string `json:"action"`
|
||||
Correction *StructuredCorrectionProposal `json:"correction"`
|
||||
}
|
||||
|
||||
// DecodeRepairResponse checks correspondence after structural schema validation.
|
||||
@@ -21,7 +26,7 @@ func DecodeRepairResponse(content []byte, expectedRef int) (RepairResponse, erro
|
||||
if err := json.Unmarshal(content, &response); err != nil {
|
||||
return RepairResponse{}, invalidRepairResponse(err)
|
||||
}
|
||||
if response.ProposalRef != expectedRef || (response.Action != "revise" || response.Correction == nil) && (response.Action != "withdraw" || response.Correction != nil) {
|
||||
if response.ProposalRef != expectedRef || (response.Decision.Action != "revise" || response.Decision.Correction == nil) && (response.Decision.Action != "withdraw" || response.Decision.Correction != nil) {
|
||||
return response, invalidRepairResponse(nil)
|
||||
}
|
||||
return response, nil
|
||||
|
||||
@@ -13,11 +13,11 @@ func TestDecodeRepairResponse(t *testing.T) {
|
||||
name, content string
|
||||
valid bool
|
||||
}{
|
||||
{"revision with deletion", `{"proposal_ref":2,"action":"revise","correction":{"id":1,"original_text":" ","corrected_text":""}}`, true},
|
||||
{"withdrawal", `{"proposal_ref":2,"action":"withdraw","correction":null}`, true},
|
||||
{"wrong reference", `{"proposal_ref":1,"action":"withdraw","correction":null}`, false},
|
||||
{"missing revision", `{"proposal_ref":2,"action":"revise","correction":null}`, false},
|
||||
{"withdrawal with revision", `{"proposal_ref":2,"action":"withdraw","correction":{"id":1}}`, false},
|
||||
{"revision with deletion", `{"proposal_ref":2,"decision":{"action":"revise","correction":{"id":1,"original_text":" ","corrected_text":""}}}`, true},
|
||||
{"withdrawal", `{"proposal_ref":2,"decision":{"action":"withdraw","correction":null}}`, true},
|
||||
{"wrong reference", `{"proposal_ref":1,"decision":{"action":"withdraw","correction":null}}`, false},
|
||||
{"missing revision", `{"proposal_ref":2,"decision":{"action":"revise","correction":null}}`, false},
|
||||
{"withdrawal with revision", `{"proposal_ref":2,"decision":{"action":"withdraw","correction":{"id":1}}}`, false},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
response, err := DecodeRepairResponse([]byte(tc.content), 2)
|
||||
@@ -25,7 +25,7 @@ func TestDecodeRepairResponse(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !tc.valid {
|
||||
if response.ProposalRef == 0 || response.Action == "" {
|
||||
if response.ProposalRef == 0 || response.Decision.Action == "" {
|
||||
t.Fatalf("missing decoded evidence: %+v", response)
|
||||
}
|
||||
var failure *structuredoutput.Failure
|
||||
|
||||
Reference in New Issue
Block a user