Daily Tech Briefing
AI 科技速览

每天 5 分钟内学习 AI。获取最新的人工智能新闻,理解其重要性,并学习如何将其应用于您的工作。

AI 快讯
AWS ML Blog · 2026/7/23 23:03:44
Best practices for applying Amazon Bedrock Guardrails to code generation workflows

Best practices for applying Amazon Bedrock Guardrails to code generation workflows

AI 中文解读
【核心亮点】AWS专门为AI编程助手制定了一套安全防护的最佳实践,既能严防生成危险代码,又不会拖慢开发速度。 【通俗解读】现在很多开发者用Claude、Codex这样的AI工具写代码,就像有个自动补全高手在旁边实时帮忙。但AI写代码也可能写出带漏洞、泄露用户信息的“问题代码”。AWS给这些AI工具装了个智能“防火墙”,能瞬间识别并拦截恶意指令、敏感信息,甚至防范黑客攻击。不过,如果配置不当,这个防火墙反而会让AI反应变慢、费用飙升。AWS这次总结的套路就是教大家怎么调教这个防火墙:在AI连续生成几千字代码的长时间会话中,既保证每句代码都被安全审查,又不让算力白白浪费。 【实际影响】以后你用AI写代码时,不再需要担心它偷偷输出危险代码或暴露用户隐私。企业可以放心地让AI助手参与大规模开发,软件漏洞更少、合规性更强。对普通用户来说,最终用到的App和网站会更安全,因为背后有层智能防护在不断过滤AI的每个输出。
<p><em>This post continues our series on best practices with Amazon Bedrock Guardrails. For the previous post, see <a href="https://aws.amazon.com/blogs/machine-learning/build-safe-generative-ai-applications-like-a-pro-best-practices-with-amazon-bedrock-guardrails/" target="_blank" rel="noopener">Build safe generative AI applications like a pro: best practices with Amazon Bedrock Guardrails</a>.</em></p> <p>AI-powered coding assistants and code generation workflows, such as Claude Code, <a href="https://aws.amazon.com/documentation-overview/kiro/" target="_blank" rel="noopener">Kiro</a>, and <a href="https://chatgpt.com/codex" target="_blank" rel="noopener">OpenAI Codex</a>, are transforming how developers write software. These tools generate code in real time through streaming responses, often producing thousands of characters across extended sessions. As organizations adopt generative AI workflows with code at scale using these assistants, it is important that unsafe code patterns are detected and blocked whenever required. <a href="https://aws.amazon.com/bedrock/guardrails/" target="_blank" rel="noopener">Amazon Bedrock Guardrails</a> helps detect and filter unsafe and undesired code content with safeguards such as content filters for content moderation, prompt attack prevention with jailbreaks, prompt injection, and prompt leakage, sensitive information filters to redact and block personally identifiable information (PII), and more.</p> <p>However, coding workflows along with agentic loops have unique throughput characteristics including long streaming outputs, concurrent developer sessions, and repetitive context evaluation. Applying Amazon Bedrock Guardrails to workflows with these characteristics without proper configuration could potentially lead to constraints such as throttling errors, increased costs, and less than optimal latency. In this post, we explain how Amazon Bedrock Guardrails can be configured for code generation workflows with coding assistants to overcome these constraints. With these best practices, you can build an efficient blueprint helping you with effective capacity planning with robust safety coverage.</p> <h2 id="why-guardrails-are-important-for-code-generation-workflows">Why guardrails are important for code generation workflows</h2> <p>Amazon Bedrock Guardrails offers comprehensive safeguards that detect and filter harmful and undesirable content from both user inputs and model responses, to help build safe generative AI applications. While these safeguards can be configured and implemented across a variety of applications, there are specific safeguards that can be used to protect harmful code patterns such as:</p> <ul> <li><strong>Detect prompt attacks</strong> – block attempts to manipulate the model into generating malicious code or bypassing instructions.</li> <li><strong>Filter sensitive information</strong> – can help block or mask sensitive information such as personally identifiable information (PII), custom regex in user inputs and model responses, catch hardcoded AWS access keys, database connection strings, or private keys before they appear in generated code.</li> <li><strong>Content moderation</strong> – detect and filter harmful content in user prompts and model responses, including content that violates your organization’s acceptable use policies.</li> <li><strong>Block denied topics</strong> – define custom topics that are used as a basis for blocking conversations related to prohibited activities, such as generating code to bypass authentication mechanisms or assisting with unauthorized access patterns.</li> </ul> <p>These safeguards are essential when AI-generated code is used in production systems.</p> <h3 id="a-scenario-when-good-guardrails-go-sideways">A scenario: When good guardrails go sideways</h3> <p>A customer system team has just rolled out Claude Code on Amazon Bedrock to 15 developers. They’ve configured a guardrail with three safeguards: prompt att
分享
阅读原文