mirror of
https://github.com/openai/codex.git
synced 2026-11-16 06:54:36 +00:00
Allow configuring the Guardian prompt template (#45516)
## What changed
Add `auto_review.experimental_policy_template` to override the Guardian prompt template in `config.toml`. Trim the configured value and ignore it when empty. Prefer the override over the model catalog template, retaining the bundled template as the final fallback.
The template's `{{ tenant_policy_config }}` placeholder is replaced with the resolved Guardian policy.
## Testing
Extend tests to cover template deserialization, trimming, precedence over the catalog template, and rendered policy text in Guardian inference requests.
GitOrigin-RevId: 85b4a8fc193a42735354894203ccbd1f738a3b58
This commit is contained in:
1 parent
fd5bf3b059
commit
520e13a4bc
8 files changed
+63
-13
No files matched your search
@@ -626,11 +626,13 @@ async fn guardian_review_session_config_disables_skill_instructions() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn guardian_review_session_config_prefers_managed_policy_and_uses_catalog_template() {
|
||||
async fn guardian_review_session_config_prefers_configured_policy_and_template() {
|
||||
let mut parent_config = crate::config::test_config().await;
|
||||
let managed_policy = "Use the managed Guardian policy.";
|
||||
let configured_template = "Configured Guardian template:\n{{ tenant_policy_config }}";
|
||||
let catalog_template = "Catalog Guardian template:\n{{ tenant_policy_config }}";
|
||||
parent_config.guardian_policy_config = Some(managed_policy.to_string());
|
||||
parent_config.guardian_policy_template = Some(configured_template.to_string());
|
||||
let model_messages = ModelMessages {
|
||||
persistent_instructions: None,
|
||||
tools: None,
|
||||
@@ -667,7 +669,7 @@ async fn guardian_review_session_config_prefers_managed_policy_and_uses_catalog_
|
||||
guardian_config.base_instructions,
|
||||
Some(guardian_policy_prompt_with_config_and_template(
|
||||
managed_policy,
|
||||
catalog_template,
|
||||
configured_template,
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,8 +47,10 @@ pub fn build_guardian_review_session_config(
|
||||
}
|
||||
let catalog_auto_review = model_messages.and_then(|messages| messages.auto_review.as_ref());
|
||||
let tenant_policy_config = parent_config.resolve_guardian_policy(model_messages);
|
||||
let policy_template = catalog_auto_review
|
||||
.and_then(|messages| messages.policy_template.as_deref())
|
||||
let policy_template = parent_config
|
||||
.guardian_policy_template
|
||||
.as_deref()
|
||||
.or_else(|| catalog_auto_review.and_then(|messages| messages.policy_template.as_deref()))
|
||||
.unwrap_or(BUNDLED_GUARDIAN_POLICY_TEMPLATE);
|
||||
guardian_config.base_instructions = Some(guardian_policy_prompt_with_config_and_template(
|
||||
tenant_policy_config,
|
||||
|
||||
Reference in new issue
Block a user