feat(tenant): enforce English output for en-US template generation
When the article locale is en-US, Chinese prompt templates could leak Chinese wording into generated titles, outlines, and article bodies. Add high-priority language-consistency guards so the model treats the Chinese template text as internal instructions and emits English only. - Append per-artifact locale guards (analyze/title/outline) in template assist prompts and an article-body guard in the generation prompt, only when locale is en-US - Reinforce locale consistency in the title/outline runtime prompts and drop retained images from the rewrite prompt - Cover the new guards with unit tests Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -107,6 +107,24 @@ func TestBuildGenerationPromptTopXRepeatsOutlineExecutionRulesInBasePrompt(t *te
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildGenerationPromptEnglishLocaleAddsHardLanguageGuard(t *testing.T) {
|
||||
promptTemplate := "你是一名内容编辑,请围绕 {{title}} 写文章。"
|
||||
prompt := buildGenerationPrompt("top_x_article", "Top X 推荐文章", &promptTemplate, map[string]interface{}{
|
||||
"title": "A Guide to Whole-home Customization",
|
||||
"locale": "en-US",
|
||||
}, "")
|
||||
|
||||
for _, expected := range []string{
|
||||
"High-priority language consistency requirement:",
|
||||
"The final article output must be entirely in natural, professional English.",
|
||||
"Treat any Chinese template text, Chinese examples, Chinese section names, or Chinese disclaimers as internal instructions only",
|
||||
} {
|
||||
if !strings.Contains(prompt, expected) {
|
||||
t.Fatalf("buildGenerationPrompt() = %q, want English language guard %q", prompt, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildGenerationPromptDoesNotAddTopXBrandRulesForOtherTemplates(t *testing.T) {
|
||||
prompt := buildGenerationPrompt("product_review", "产品评测", nil, map[string]interface{}{
|
||||
"product_name": "测试产品",
|
||||
|
||||
Reference in New Issue
Block a user