diff --git a/internal/contracts/guard/v1/guard.pb.go b/internal/contracts/guard/v1/guard.pb.go index bb6221134..8500ba48f 100644 --- a/internal/contracts/guard/v1/guard.pb.go +++ b/internal/contracts/guard/v1/guard.pb.go @@ -814,7 +814,11 @@ type JudgeResponse struct { Ceiling Ceiling `protobuf:"varint,1,opt,name=ceiling,proto3,enum=guard.v1.Ceiling" json:"ceiling,omitempty"` Findings []*Finding `protobuf:"bytes,2,rep,name=findings,proto3" json:"findings,omitempty"` // blind_spots are what the guard could not see. - BlindSpots []string `protobuf:"bytes,3,rep,name=blind_spots,json=blindSpots,proto3" json:"blind_spots,omitempty"` + BlindSpots []string `protobuf:"bytes,3,rep,name=blind_spots,json=blindSpots,proto3" json:"blind_spots,omitempty"` + // judges is every model judgement the verdict rests on, clean answers + // included. A guard that asked a model records the answer here, so the + // verdict can be audited without asking the model again. + Judges []*JudgeRecord `protobuf:"bytes,4,rep,name=judges,proto3" json:"judges,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -870,6 +874,149 @@ func (x *JudgeResponse) GetBlindSpots() []string { return nil } +func (x *JudgeResponse) GetJudges() []*JudgeRecord { + if x != nil { + return x.Judges + } + return nil +} + +// JudgeRecord is what one model judge answered and what it was judged on. +type JudgeRecord struct { + state protoimpl.MessageState `protogen:"open.v1"` + // model is the model that judged. + Model string `protobuf:"bytes,1,opt,name=model,proto3" json:"model,omitempty"` + // result_id identifies the judge's result with the service that ran it. + ResultId string `protobuf:"bytes,2,opt,name=result_id,json=resultId,proto3" json:"result_id,omitempty"` + // answer is the choice the judge settled on, such as "complies". + Answer string `protobuf:"bytes,3,opt,name=answer,proto3" json:"answer,omitempty"` + Confidence float64 `protobuf:"fixed64,4,opt,name=confidence,proto3" json:"confidence,omitempty"` + // reason is the judge's own reasoning, or why the call failed. + Reason string `protobuf:"bytes,5,opt,name=reason,proto3" json:"reason,omitempty"` + // basis is the text the judge was given beyond the action itself, such as + // the policy rules. basis_digest is its SHA-256 in hex. + Basis string `protobuf:"bytes,6,opt,name=basis,proto3" json:"basis,omitempty"` + BasisDigest string `protobuf:"bytes,7,opt,name=basis_digest,json=basisDigest,proto3" json:"basis_digest,omitempty"` + // answers is every question's answer as JSON: choice, probabilities and + // confidence. + Answers []byte `protobuf:"bytes,8,opt,name=answers,proto3" json:"answers,omitempty"` + // trusted says the judge has passed its recorded eval, so its verdict sets + // a ceiling. When false, advisory_reason says why. + Trusted bool `protobuf:"varint,9,opt,name=trusted,proto3" json:"trusted,omitempty"` + AdvisoryReason string `protobuf:"bytes,10,opt,name=advisory_reason,json=advisoryReason,proto3" json:"advisory_reason,omitempty"` + // eval_date is the date of the eval the judge's standing comes from. + EvalDate string `protobuf:"bytes,11,opt,name=eval_date,json=evalDate,proto3" json:"eval_date,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *JudgeRecord) Reset() { + *x = JudgeRecord{} + mi := &file_guard_v1_guard_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *JudgeRecord) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*JudgeRecord) ProtoMessage() {} + +func (x *JudgeRecord) ProtoReflect() protoreflect.Message { + mi := &file_guard_v1_guard_proto_msgTypes[11] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use JudgeRecord.ProtoReflect.Descriptor instead. +func (*JudgeRecord) Descriptor() ([]byte, []int) { + return file_guard_v1_guard_proto_rawDescGZIP(), []int{11} +} + +func (x *JudgeRecord) GetModel() string { + if x != nil { + return x.Model + } + return "" +} + +func (x *JudgeRecord) GetResultId() string { + if x != nil { + return x.ResultId + } + return "" +} + +func (x *JudgeRecord) GetAnswer() string { + if x != nil { + return x.Answer + } + return "" +} + +func (x *JudgeRecord) GetConfidence() float64 { + if x != nil { + return x.Confidence + } + return 0 +} + +func (x *JudgeRecord) GetReason() string { + if x != nil { + return x.Reason + } + return "" +} + +func (x *JudgeRecord) GetBasis() string { + if x != nil { + return x.Basis + } + return "" +} + +func (x *JudgeRecord) GetBasisDigest() string { + if x != nil { + return x.BasisDigest + } + return "" +} + +func (x *JudgeRecord) GetAnswers() []byte { + if x != nil { + return x.Answers + } + return nil +} + +func (x *JudgeRecord) GetTrusted() bool { + if x != nil { + return x.Trusted + } + return false +} + +func (x *JudgeRecord) GetAdvisoryReason() string { + if x != nil { + return x.AdvisoryReason + } + return "" +} + +func (x *JudgeRecord) GetEvalDate() string { + if x != nil { + return x.EvalDate + } + return "" +} + var File_guard_v1_guard_proto protoreflect.FileDescriptor const file_guard_v1_guard_proto_rawDesc = "" + @@ -925,12 +1072,28 @@ const file_guard_v1_guard_proto_rawDesc = "" + "\aFinding\x12\x12\n" + "\x04text\x18\x01 \x01(\tR\x04text\x12\x1a\n" + "\bevidence\x18\x02 \x01(\tR\bevidence\x12.\n" + - "\bstrength\x18\x03 \x01(\x0e2\x12.guard.v1.StrengthR\bstrength\"\x8c\x01\n" + + "\bstrength\x18\x03 \x01(\x0e2\x12.guard.v1.StrengthR\bstrength\"\xbb\x01\n" + "\rJudgeResponse\x12+\n" + "\aceiling\x18\x01 \x01(\x0e2\x11.guard.v1.CeilingR\aceiling\x12-\n" + "\bfindings\x18\x02 \x03(\v2\x11.guard.v1.FindingR\bfindings\x12\x1f\n" + "\vblind_spots\x18\x03 \x03(\tR\n" + - "blindSpots*\x95\x01\n" + + "blindSpots\x12-\n" + + "\x06judges\x18\x04 \x03(\v2\x15.guard.v1.JudgeRecordR\x06judges\"\xc3\x02\n" + + "\vJudgeRecord\x12\x14\n" + + "\x05model\x18\x01 \x01(\tR\x05model\x12\x1b\n" + + "\tresult_id\x18\x02 \x01(\tR\bresultId\x12\x16\n" + + "\x06answer\x18\x03 \x01(\tR\x06answer\x12\x1e\n" + + "\n" + + "confidence\x18\x04 \x01(\x01R\n" + + "confidence\x12\x16\n" + + "\x06reason\x18\x05 \x01(\tR\x06reason\x12\x14\n" + + "\x05basis\x18\x06 \x01(\tR\x05basis\x12!\n" + + "\fbasis_digest\x18\a \x01(\tR\vbasisDigest\x12\x18\n" + + "\aanswers\x18\b \x01(\fR\aanswers\x12\x18\n" + + "\atrusted\x18\t \x01(\bR\atrusted\x12'\n" + + "\x0fadvisory_reason\x18\n" + + " \x01(\tR\x0eadvisoryReason\x12\x1b\n" + + "\teval_date\x18\v \x01(\tR\bevalDate*\x95\x01\n" + "\rReversibility\x12\x1d\n" + "\x19REVERSIBILITY_UNSPECIFIED\x10\x00\x12&\n" + "\"REVERSIBILITY_UNDONE_AUTOMATICALLY\x10\x01\x12\x1d\n" + @@ -968,7 +1131,7 @@ func file_guard_v1_guard_proto_rawDescGZIP() []byte { } var file_guard_v1_guard_proto_enumTypes = make([]protoimpl.EnumInfo, 3) -var file_guard_v1_guard_proto_msgTypes = make([]protoimpl.MessageInfo, 13) +var file_guard_v1_guard_proto_msgTypes = make([]protoimpl.MessageInfo, 14) var file_guard_v1_guard_proto_goTypes = []any{ (Reversibility)(0), // 0: guard.v1.Reversibility (Ceiling)(0), // 1: guard.v1.Ceiling @@ -984,35 +1147,37 @@ var file_guard_v1_guard_proto_goTypes = []any{ (*Evidence)(nil), // 11: guard.v1.Evidence (*Finding)(nil), // 12: guard.v1.Finding (*JudgeResponse)(nil), // 13: guard.v1.JudgeResponse - nil, // 14: guard.v1.ConfigureRequest.SettingsEntry - nil, // 15: guard.v1.ConfigureRequest.SecretsEntry - (*durationpb.Duration)(nil), // 16: google.protobuf.Duration - (*timestamppb.Timestamp)(nil), // 17: google.protobuf.Timestamp + (*JudgeRecord)(nil), // 14: guard.v1.JudgeRecord + nil, // 15: guard.v1.ConfigureRequest.SettingsEntry + nil, // 16: guard.v1.ConfigureRequest.SecretsEntry + (*durationpb.Duration)(nil), // 17: google.protobuf.Duration + (*timestamppb.Timestamp)(nil), // 18: google.protobuf.Timestamp } var file_guard_v1_guard_proto_depIdxs = []int32{ - 14, // 0: guard.v1.ConfigureRequest.settings:type_name -> guard.v1.ConfigureRequest.SettingsEntry - 15, // 1: guard.v1.ConfigureRequest.secrets:type_name -> guard.v1.ConfigureRequest.SecretsEntry + 15, // 0: guard.v1.ConfigureRequest.settings:type_name -> guard.v1.ConfigureRequest.SettingsEntry + 16, // 1: guard.v1.ConfigureRequest.secrets:type_name -> guard.v1.ConfigureRequest.SecretsEntry 0, // 2: guard.v1.Effect.reversibility:type_name -> guard.v1.Reversibility 8, // 3: guard.v1.JudgeRequest.target:type_name -> guard.v1.Target 7, // 4: guard.v1.JudgeRequest.effect:type_name -> guard.v1.Effect 9, // 5: guard.v1.JudgeRequest.run:type_name -> guard.v1.RunContext - 16, // 6: guard.v1.JudgeRequest.deadline:type_name -> google.protobuf.Duration - 17, // 7: guard.v1.JudgeRequest.at:type_name -> google.protobuf.Timestamp + 17, // 6: guard.v1.JudgeRequest.deadline:type_name -> google.protobuf.Duration + 18, // 7: guard.v1.JudgeRequest.at:type_name -> google.protobuf.Timestamp 11, // 8: guard.v1.JudgeRequest.evidence:type_name -> guard.v1.Evidence 2, // 9: guard.v1.Finding.strength:type_name -> guard.v1.Strength 1, // 10: guard.v1.JudgeResponse.ceiling:type_name -> guard.v1.Ceiling 12, // 11: guard.v1.JudgeResponse.findings:type_name -> guard.v1.Finding - 3, // 12: guard.v1.GuardService.Configure:input_type -> guard.v1.ConfigureRequest - 5, // 13: guard.v1.GuardService.Describe:input_type -> guard.v1.DescribeRequest - 10, // 14: guard.v1.GuardService.Judge:input_type -> guard.v1.JudgeRequest - 4, // 15: guard.v1.GuardService.Configure:output_type -> guard.v1.ConfigureResponse - 6, // 16: guard.v1.GuardService.Describe:output_type -> guard.v1.DescribeResponse - 13, // 17: guard.v1.GuardService.Judge:output_type -> guard.v1.JudgeResponse - 15, // [15:18] is the sub-list for method output_type - 12, // [12:15] is the sub-list for method input_type - 12, // [12:12] is the sub-list for extension type_name - 12, // [12:12] is the sub-list for extension extendee - 0, // [0:12] is the sub-list for field type_name + 14, // 12: guard.v1.JudgeResponse.judges:type_name -> guard.v1.JudgeRecord + 3, // 13: guard.v1.GuardService.Configure:input_type -> guard.v1.ConfigureRequest + 5, // 14: guard.v1.GuardService.Describe:input_type -> guard.v1.DescribeRequest + 10, // 15: guard.v1.GuardService.Judge:input_type -> guard.v1.JudgeRequest + 4, // 16: guard.v1.GuardService.Configure:output_type -> guard.v1.ConfigureResponse + 6, // 17: guard.v1.GuardService.Describe:output_type -> guard.v1.DescribeResponse + 13, // 18: guard.v1.GuardService.Judge:output_type -> guard.v1.JudgeResponse + 16, // [16:19] is the sub-list for method output_type + 13, // [13:16] is the sub-list for method input_type + 13, // [13:13] is the sub-list for extension type_name + 13, // [13:13] is the sub-list for extension extendee + 0, // [0:13] is the sub-list for field type_name } func init() { file_guard_v1_guard_proto_init() } @@ -1026,7 +1191,7 @@ func file_guard_v1_guard_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_guard_v1_guard_proto_rawDesc), len(file_guard_v1_guard_proto_rawDesc)), NumEnums: 3, - NumMessages: 13, + NumMessages: 14, NumExtensions: 0, NumServices: 1, }, diff --git a/modules/connectors/guards.go b/modules/connectors/guards.go index 2e122b98f..a11f694e8 100644 --- a/modules/connectors/guards.go +++ b/modules/connectors/guards.go @@ -56,6 +56,23 @@ type GuardAnswer struct { Ceiling int Findings []GuardFinding BlindSpots []string + Judges []GuardJudge +} + +// GuardJudge is what one model judge answered and what it was judged on. +// Answers is the judge service's answers as JSON. +type GuardJudge struct { + Model string + ResultID string + Answer string + Confidence float64 + Reason string + Basis string + BasisDigest string + Answers []byte + Trusted bool + AdvisoryReason string + EvalDate string } // Guard is a running guard extension. @@ -107,6 +124,13 @@ func (g *Guard) Judge(ctx context.Context, r GuardRequest) (GuardAnswer, error) for _, f := range resp.GetFindings() { a.Findings = append(a.Findings, GuardFinding{Text: f.GetText(), Evidence: f.GetEvidence(), Strength: strengthName(f.GetStrength())}) } + for _, j := range resp.GetJudges() { + a.Judges = append(a.Judges, GuardJudge{ + Model: j.GetModel(), ResultID: j.GetResultId(), Answer: j.GetAnswer(), Confidence: j.GetConfidence(), + Reason: j.GetReason(), Basis: j.GetBasis(), BasisDigest: j.GetBasisDigest(), Answers: j.GetAnswers(), + Trusted: j.GetTrusted(), AdvisoryReason: j.GetAdvisoryReason(), EvalDate: j.GetEvalDate(), + }) + } return a, nil } diff --git a/modules/judgement/extensions.go b/modules/judgement/extensions.go index 1bc08d5f3..042e4a345 100644 --- a/modules/judgement/extensions.go +++ b/modules/judgement/extensions.go @@ -86,5 +86,12 @@ func (e extensionGuard) Judge(ctx context.Context, a Action) (Verdict, error) { for _, f := range ans.Findings { v.Findings = append(v.Findings, Finding{Text: f.Text, Evidence: f.Evidence, Strength: f.Strength}) } + for _, j := range ans.Judges { + v.Judges = append(v.Judges, JudgeRecord{ + Model: j.Model, ResultID: j.ResultID, Answer: j.Answer, Confidence: j.Confidence, Reason: j.Reason, + Basis: j.Basis, BasisDigest: j.BasisDigest, Answers: j.Answers, + Trusted: j.Trusted, AdvisoryReason: j.AdvisoryReason, EvalDate: j.EvalDate, + }) + } return v, nil } diff --git a/modules/judgement/judgement.go b/modules/judgement/judgement.go index 8e3d049d5..3430301f6 100644 --- a/modules/judgement/judgement.go +++ b/modules/judgement/judgement.go @@ -72,6 +72,27 @@ type Finding struct { Strength string `json:"strength,omitzero"` } +// JudgeRecord is what one model judge answered and what it was judged on, +// kept whole so the verdict can be audited without asking the model again. +type JudgeRecord struct { + Model string `json:"model,omitzero"` + ResultID string `json:"result_id,omitzero"` + Answer string `json:"answer,omitzero"` + Confidence float64 `json:"confidence,omitzero"` + Reason string `json:"reason,omitzero"` + // Basis is the text the judge was given beyond the action, and + // BasisDigest its SHA-256. + Basis string `json:"basis,omitzero"` + BasisDigest string `json:"basis_digest,omitzero"` + // Answers is the judge service's answers as it returned them. + Answers jsontext.Value `json:"answers,omitzero"` + // Trusted says the judge has passed its eval; AdvisoryReason says why + // not when it hasn't. + Trusted bool `json:"trusted,omitzero"` + AdvisoryReason string `json:"advisory_reason,omitzero"` + EvalDate string `json:"eval_date,omitzero"` +} + // Verdict is one guard's judgement of one action. type Verdict struct { Guard string `json:"guard"` @@ -82,6 +103,8 @@ type Verdict struct { Ceiling Level `json:"ceiling"` Findings []Finding `json:"findings,omitzero"` BlindSpots []string `json:"blind_spots,omitzero"` + // Judges is every model judgement the verdict rests on. + Judges []JudgeRecord `json:"judges,omitzero"` // Advisory verdicts are recorded and set no ceiling. Advisory bool `json:"advisory,omitzero"` // Failed says why the guard couldn't answer; its ceiling is then diff --git a/proto/guard/v1/guard.proto b/proto/guard/v1/guard.proto index 23450544e..285fab2e5 100644 --- a/proto/guard/v1/guard.proto +++ b/proto/guard/v1/guard.proto @@ -122,4 +122,34 @@ message JudgeResponse { repeated Finding findings = 2; // blind_spots are what the guard could not see. repeated string blind_spots = 3; + // judges is every model judgement the verdict rests on, clean answers + // included. A guard that asked a model records the answer here, so the + // verdict can be audited without asking the model again. + repeated JudgeRecord judges = 4; +} + +// JudgeRecord is what one model judge answered and what it was judged on. +message JudgeRecord { + // model is the model that judged. + string model = 1; + // result_id identifies the judge's result with the service that ran it. + string result_id = 2; + // answer is the choice the judge settled on, such as "complies". + string answer = 3; + double confidence = 4; + // reason is the judge's own reasoning, or why the call failed. + string reason = 5; + // basis is the text the judge was given beyond the action itself, such as + // the policy rules. basis_digest is its SHA-256 in hex. + string basis = 6; + string basis_digest = 7; + // answers is every question's answer as JSON: choice, probabilities and + // confidence. + bytes answers = 8; + // trusted says the judge has passed its recorded eval, so its verdict sets + // a ceiling. When false, advisory_reason says why. + bool trusted = 9; + string advisory_reason = 10; + // eval_date is the date of the eval the judge's standing comes from. + string eval_date = 11; } diff --git a/ui/src/archie/ActionTrailView.vue b/ui/src/archie/ActionTrailView.vue index b9da711e3..520d736be 100644 --- a/ui/src/archie/ActionTrailView.vue +++ b/ui/src/archie/ActionTrailView.vue @@ -64,6 +64,24 @@ const ceilingTone = (v: Verdict): Tone => (v.failed ? "warn" : "secondary"); {{ f.text }}: {{ f.evidence }} Blind spot: {{ b }} +
{{ j.basis }}
+ {{ json(j.answers) }}
+ {{ decision.reason }}
diff --git a/ui/src/archie/api.ts b/ui/src/archie/api.ts index cb817fa22..95092c165 100644 --- a/ui/src/archie/api.ts +++ b/ui/src/archie/api.ts @@ -79,11 +79,26 @@ export interface TrailEntry { unknown?: boolean; } +export interface JudgeRecord { + model?: string; + result_id?: string; + answer?: string; + confidence?: number; + reason?: string; + basis?: string; + basis_digest?: string; + answers?: unknown; + trusted?: boolean; + advisory_reason?: string; + eval_date?: string; +} + export interface Verdict { guard: string; ceiling: string; findings?: { text: string; evidence?: string }[]; blind_spots?: string[]; + judges?: JudgeRecord[]; advisory?: boolean; failed?: string; }