Support model catalog templates for Guardian policy prompts (#33177)

## What changed

- Add an optional `policy_template` field to auto-review model messages.
- Build Guardian instructions from the catalog template when present, while
  preserving the existing precedence for managed and catalog policy content.
- Fall back independently to the bundled template and bundled policy, and
  preserve explicit empty catalog values.

## Testing

- Cover missing and empty template deserialization, policy precedence, bundled
  fallbacks, and Guardian prewarm instructions.

GitOrigin-RevId: 93116dadbc9bf40527882844a428caed4159fff6
This commit is contained in:
rhan-oai authored and copyberry committed 2026-07-14 22:01:11 +00:00
1 parent 6e215e0db5
commit 68c6e5df2b
9 files changed
+156 -44

No files matched your search

+41
View File
@@ -518,6 +518,7 @@ pub struct ApprovalMessages {
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
pub struct AutoReviewMessages {
pub policy: Option<String>,
pub policy_template: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, TS, JsonSchema)]
@@ -777,6 +778,46 @@ mod tests {
);
}
#[test]
fn auto_review_messages_preserve_missing_and_empty_template_values() {
let missing_template: ModelMessages = from_str(
r#"{
"instructions_template": null,
"instructions_variables": null,
"auto_review": {
"policy": "policy"
}
}"#,
)
.expect("auto-review messages should deserialize without a policy template");
let empty_template: ModelMessages = from_str(
r#"{
"instructions_template": null,
"instructions_variables": null,
"auto_review": {
"policy": "policy",
"policy_template": ""
}
}"#,
)
.expect("auto-review messages should deserialize with an empty policy template");
assert_eq!(
missing_template.auto_review,
Some(AutoReviewMessages {
policy: Some("policy".to_string()),
policy_template: None,
})
);
assert_eq!(
empty_template.auto_review,
Some(AutoReviewMessages {
policy: Some("policy".to_string()),
policy_template: Some(String::new()),
})
);
}
#[test]
fn permission_messages_preserve_missing_and_empty_values() {
let messages: ModelMessages = from_str(