{"id":53658,"date":"2025-08-20T09:07:31","date_gmt":"2025-08-19T23:07:31","guid":{"rendered":"https:\/\/www.cloudproinc.com.au\/?p=53658"},"modified":"2025-08-20T09:07:34","modified_gmt":"2025-08-19T23:07:34","slug":"building-guardrails-in-the-openai-agent-sdk","status":"publish","type":"post","link":"https:\/\/cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/","title":{"rendered":"Building Guardrails in the OpenAI Agent SDK"},"content":{"rendered":"\n<p>This OpenAI Agent post &#8220;Building Guardrails in the OpenAI Agent SDK&#8221; will explain how to implement a gurdrail system that protact the Agent from misuse.<\/p>\n\n\n\n<!--more-->\n\n\n\n<div class=\"wp-block-yoast-seo-table-of-contents yoast-table-of-contents\"><h2>Table of contents<\/h2><ul><li><a href=\"#h-what-are-guardrails\" data-level=\"2\">What Are Guardrails?<\/a><\/li><li><a href=\"#h-example-a-python-only-guardrail\" data-level=\"2\">Example: A Python-Only Guardrail<\/a><\/li><li><a href=\"#h-integrating-guardrails-into-the-main-agent\" data-level=\"2\">Integrating Guardrails Into the Main Agent<\/a><\/li><li><a href=\"#h-testing-the-guardrail\" data-level=\"2\">Testing the Guardrail<\/a><\/li><li><a href=\"#h-why-guardrails-matter\" data-level=\"2\">Why Guardrails Matter<\/a><\/li><li><a href=\"#h-guardrails-as-part-of-a-larger-agent-design\" data-level=\"2\">Guardrails as Part of a Larger Agent Design<\/a><\/li><li><a href=\"#h-conclusion\" data-level=\"2\">Conclusion<\/a><\/li><\/ul><\/div>\n\n\n\n<p>In my <a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/18\/build-a-multi-agent-assistant-in-python-with-the-openai-agents-sdk\/\">previous article on the OpenAI Agent SDK<\/a>, I showed how to build an AI agent using the SDK, We looked at an example where an agent could generate secure passwords, fetch the current time, and hand off coding questions to a specialist Python tutor sub-agent.<\/p>\n\n\n\n<p>That introduction laid the foundation for building powerful, multi-purpose agents. But in production environments, there\u2019s an equally important question: <strong>how do you keep agents focused and safe?<\/strong><\/p>\n\n\n\n<p>This is where <strong>guardrails<\/strong> come in.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-are-guardrails\">What Are Guardrails?<\/h2>\n\n\n\n<p>Guardrails are constraints that define what an agent should or should not do. They act as protective boundaries around the agent\u2019s behavior, ensuring that it only processes valid or relevant input. Without them, an agent might attempt to answer queries outside its intended scope, leading to incorrect, misleading, or even risky outputs.<\/p>\n\n\n\n<p>For example, imagine you\u2019ve deployed a Python tutoring agent for a learning platform. You wouldn\u2019t want students asking it about fitness routines, political debates, or general trivia\u2014the agent should only handle <strong>Python coding questions<\/strong>.<\/p>\n\n\n\n<p>The OpenAI Agent SDK provides a mechanism for exactly this: <strong>input guardrails<\/strong>. These allow you to classify incoming prompts and decide whether they should be processed\u2014or blocked.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"683\" data-src=\"\/wp-content\/uploads\/2025\/08\/Guardrails-1024x683.png\" alt=\"Building Guardrails in the OpenAI Agent SDK\" class=\"wp-image-53659 lazyload\" data-srcset=\"\/wp-content\/uploads\/2025\/08\/Guardrails-1024x683.png 1024w, \/wp-content\/uploads\/2025\/08\/Guardrails-300x200.png 300w, \/wp-content\/uploads\/2025\/08\/Guardrails-768x512.png 768w, \/wp-content\/uploads\/2025\/08\/Guardrails-1080x720.png 1080w, \/wp-content\/uploads\/2025\/08\/Guardrails-1280x853.png 1280w, \/wp-content\/uploads\/2025\/08\/Guardrails-980x653.png 980w, \/wp-content\/uploads\/2025\/08\/Guardrails-480x320.png 480w, \/wp-content\/uploads\/2025\/08\/Guardrails.png 1536w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/683;\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-a-python-only-guardrail\">Example: A Python-Only Guardrail<\/h2>\n\n\n\n<p>Let\u2019s look at the implementation of a simple guardrail that ensures the user\u2019s query relates to Python code. If the question is unrelated, the guardrail trips a \u201ctripwire\u201d and the request is blocked.<\/p>\n\n\n\n<p>Here\u2019s the heart of the code:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-d2ad611a78907adf0543b7c0ccc54cd5\"><code>class PythonOutput(BaseModel):\n    is_python: bool\n    reasoning: str\n\nguardrail_agent = Agent(\n    name=\"Guardrail check\",\n    instructions=\"Check if the user is asking about python code.\",\n    output_type=PythonOutput,\n)\n\nasync def python_guardrail(ctx, agent, input_data):\n    result = await Runner.run(guardrail_agent, input_data, context=ctx.context)\n    final_output = result.final_output_as(PythonOutput)\n    return GuardrailFunctionOutput(\n        output_info=final_output,\n        tripwire_triggered=not final_output.is_python,\n    )\n<\/code><\/pre>\n\n\n\n<p>A dedicated <code>guardrail_agent<\/code> is used to classify whether a question is Python-related. Its output is structured as a <code>PythonOutput<\/code> model, returning both a Boolean (<code>is_python<\/code>) and a reasoning string for transparency.<\/p>\n\n\n\n<p>If <code>is_python<\/code> is <code>False<\/code>, the guardrail function returns a <code>GuardrailFunctionOutput<\/code> with <code>tripwire_triggered=True<\/code>, effectively blocking the request.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-integrating-guardrails-into-the-main-agent\">Integrating Guardrails Into the Main Agent<\/h2>\n\n\n\n<p>Once defined, the guardrail is attached to the main agent via <code>InputGuardrail<\/code>. Here\u2019s how it looks:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-a449295595cd68fa70cb0096ab63925e\"><code>triage_agent = Agent(\n    name=\"My Agent\",\n    instructions=(\n        \"You are a helpful agent. You can generate passwords, \"\n        \"provide the current time, and hand off to a Python tutor agent \"\n        \"for code-related queries.\"\n    ),\n    tools=&#91;generate_password, get_time],\n    handoffs=&#91;python_tutor_agent],\n    input_guardrails=&#91;\n        InputGuardrail(guardrail_function=python_guardrail),\n    ],\n)\n<\/code><\/pre>\n\n\n\n<p>This ensures that <strong>all input<\/strong> passed to the agent is checked before execution.<\/p>\n\n\n\n<p>If the input doesn\u2019t pass the Python-only check, the SDK raises an <code>InputGuardrailTripwireTriggered<\/code> exception. Developers can catch this exception and decide how to handle it\u2014for example, logging it, sending a polite error message to the user, or redirecting them to another resource.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-testing-the-guardrail\">Testing the Guardrail<\/h2>\n\n\n\n<p>Here\u2019s a quick test:<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-6b4502398dfadfb6f54a01cd26043759\"><code>try:\n    result = await Runner.run(triage_agent, \"What is an air dyne bike?\")\n    print(result.final_output)\nexcept InputGuardrailTripwireTriggered as e:\n    print(\"Guardrail blocked this input:\", e)\n\ntry:\n    result = await Runner.run(triage_agent, \"Explain what a class is in Python.\")\n    print(result.final_output)\nexcept InputGuardrailTripwireTriggered as e:\n    print(\"Guardrail blocked this input:\", e)\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The first input, about a fitness bike, is blocked by the guardrail.<\/li>\n\n\n\n<li>The second input, asking about Python classes, passes through and is handled by the Python tutor sub-agent.<\/li>\n<\/ul>\n\n\n\n<p>This demonstrates how <strong>guardrails enforce scope<\/strong> while still allowing flexibility within their boundaries.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-why-guardrails-matter\">Why Guardrails Matter<\/h2>\n\n\n\n<p>Adding guardrails provides several benefits:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Focus and Relevance<\/strong><br>Agents won\u2019t drift into answering unrelated questions, improving user trust and experience.<\/li>\n\n\n\n<li><strong>Safety and Compliance<\/strong><br>In enterprise settings, guardrails help prevent outputs that violate business rules or compliance requirements.<\/li>\n\n\n\n<li><strong>Transparency and Debugging<\/strong><br>Because the guardrail\u2019s decision is based on structured output, developers can log both the classification (<code>is_python<\/code>) and the reasoning for auditing.<\/li>\n\n\n\n<li><strong>Extensibility<\/strong><br>The same pattern can be extended. For example, you could create guardrails for:\n<ul class=\"wp-block-list\">\n<li>Restricting to specific domains (e.g., finance only).<\/li>\n\n\n\n<li>Blocking sensitive topics.<\/li>\n\n\n\n<li>Filtering based on user roles or permissions.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-guardrails-as-part-of-a-larger-agent-design\">Guardrails as Part of a Larger Agent Design<\/h2>\n\n\n\n<p>In my <a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/18\/build-a-multi-agent-assistant-in-python-with-the-openai-agents-sdk\/\">earlier post<\/a> about the OpenAI Agent SDK, we explored how agents can combine tools and handoffs to create flexible multi-agent workflows. Guardrails add another layer: <strong>control and governance<\/strong>.<\/p>\n\n\n\n<p>Think of it this way:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Tools<\/strong> give your agent capabilities.<\/li>\n\n\n\n<li><strong>Handoffs<\/strong> let it collaborate with specialists.<\/li>\n\n\n\n<li><strong>Guardrails<\/strong> keep it safe and on track.<\/li>\n<\/ul>\n\n\n\n<p>Together, they form a powerful framework for building production-ready AI agents.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2>\n\n\n\n<p>Guardrails in the OpenAI Agent SDK are not just technical niceties\u2014they\u2019re essential for building safe, reliable, and business-ready AI systems.<\/p>\n\n\n\n<p>By implementing even a simple Python-only guardrail, as we did in this example, you can enforce strict domain boundaries and prevent misuse. As your agent ecosystem grows, combining tools, handoffs, and guardrails will give you the right balance between power and safety.<\/p>\n\n\n\n<p>If you\u2019re experimenting with the Agent SDK, I encourage you to start small\u2014add a guardrail to your existing agent from the <a href=\"https:\/\/chatgpt.com\/c\/68a5007a-87cc-832e-83b0-796eb4c0f413#\">previous tutorial<\/a>. From there, think about what \u201crules of engagement\u201d your agents need in your specific environment. Guardrails give you the mechanism to implement them cleanly and transparently.<\/p>\n\n\n\n<ul class=\"wp-block-yoast-seo-related-links yoast-seo-related-links\">\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/18\/build-a-multi-agent-assistant-in-python-with-the-openai-agents-sdk\/\">Build a Multi-Agent Assistant in Python with the OpenAI Agents SDK<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/07\/08\/develop-and-deploy-teams-apps-with-m365-agents-toolkit\/\">Develop and Deploy Teams Apps With M365 Agents Toolkit<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/cloudproinc.com.au\/index.php\/2022\/02\/23\/five-ways-to-secure-your-microsoft-365-tenant-tips-to-keep-your-data-safe\/\">Five Ways to Secure Your Microsoft 365 Tenant: Tips to Keep Your Data Safe<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/04\/18\/setting-up-azure-mcp-server-with-vs-code\/\">Setting Up Azure MCP Server with VS Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/04\/28\/creating-an-mcp-server-in-c-to-call-openai-and-list-files\/\">Creating an MCP Server in C# to Call OpenAI and List Files<\/a><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This OpenAI Agent post &#8220;Building Guardrails in the OpenAI Agent SDK&#8221; will explain how to implement a gurdrail system that protact the Agent from misuse.<\/p>\n","protected":false},"author":1,"featured_media":53659,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_yoast_wpseo_focuskw":"Building Guardrails in the OpenAI Agent SDK","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Learn about building guardrails in the OpenAI Agent SDK to protect agents from misuse and ensure safe operations.","_yoast_wpseo_opengraph-title":"","_yoast_wpseo_opengraph-description":"","_yoast_wpseo_twitter-title":"","_yoast_wpseo_twitter-description":"","_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[24,80,13,53,79],"tags":[],"class_list":["post-53658","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai","category-ai-agents","category-blog","category-openai","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Building Guardrails in the OpenAI Agent SDK - CPI Consulting<\/title>\n<meta name=\"description\" content=\"Learn about building guardrails in the OpenAI Agent SDK to protect agents from misuse and ensure safe operations.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building Guardrails in the OpenAI Agent SDK\" \/>\n<meta property=\"og:description\" content=\"Learn about building guardrails in the OpenAI Agent SDK to protect agents from misuse and ensure safe operations.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/\" \/>\n<meta property=\"og:site_name\" content=\"CPI Consulting\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-19T23:07:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-19T23:07:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudproinc.com.au\/wp-content\/uploads\/2025\/08\/Guardrails.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1536\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CPI Staff\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CPI Staff\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/\"},\"author\":{\"name\":\"CPI Staff\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\"},\"headline\":\"Building Guardrails in the OpenAI Agent SDK\",\"datePublished\":\"2025-08-19T23:07:31+00:00\",\"dateModified\":\"2025-08-19T23:07:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/\"},\"wordCount\":817,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/Guardrails.png\",\"articleSection\":[\"AI\",\"AI Agents\",\"Blog\",\"OpenAI\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/#respond\"]}],\"accessibilityFeature\":[\"tableOfContents\"]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/\",\"url\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/\",\"name\":\"Building Guardrails in the OpenAI Agent SDK - CPI Consulting\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/#primaryimage\"},\"thumbnailUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/Guardrails.png\",\"datePublished\":\"2025-08-19T23:07:31+00:00\",\"dateModified\":\"2025-08-19T23:07:34+00:00\",\"description\":\"Learn about building guardrails in the OpenAI Agent SDK to protect agents from misuse and ensure safe operations.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/#primaryimage\",\"url\":\"\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/Guardrails.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2025\\\/08\\\/Guardrails.png\",\"width\":1536,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.cloudproinc.com.au\\\/index.php\\\/2025\\\/08\\\/20\\\/building-guardrails-in-the-openai-agent-sdk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cloudproinc.com.au\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building Guardrails in the OpenAI Agent SDK\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#website\",\"url\":\"https:\\\/\\\/cloudproinc.com.au\\\/\",\"name\":\"Cloud Pro Inc - CPI Consulting Pty Ltd\",\"description\":\"Cloud, AI &amp; Cybersecurity Consulting | Melbourne\",\"publisher\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cloudproinc.com.au\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#organization\",\"name\":\"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd\",\"url\":\"https:\\\/\\\/cloudproinc.com.au\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/favfinalfile.png\",\"contentUrl\":\"\\\/wp-content\\\/uploads\\\/2022\\\/01\\\/favfinalfile.png\",\"width\":500,\"height\":500,\"caption\":\"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/cloudproinc.com.au\\\/#\\\/schema\\\/person\\\/192eeeb0ce91062126ce3822ae88fe6e\",\"name\":\"CPI Staff\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g\",\"caption\":\"CPI Staff\"},\"sameAs\":[\"http:\\\/\\\/www.cloudproinc.com.au\"],\"url\":\"https:\\\/\\\/cloudproinc.com.au\\\/index.php\\\/author\\\/cpiadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Building Guardrails in the OpenAI Agent SDK - CPI Consulting","description":"Learn about building guardrails in the OpenAI Agent SDK to protect agents from misuse and ensure safe operations.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/","og_locale":"en_US","og_type":"article","og_title":"Building Guardrails in the OpenAI Agent SDK","og_description":"Learn about building guardrails in the OpenAI Agent SDK to protect agents from misuse and ensure safe operations.","og_url":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/","og_site_name":"CPI Consulting","article_published_time":"2025-08-19T23:07:31+00:00","article_modified_time":"2025-08-19T23:07:34+00:00","og_image":[{"width":1536,"height":1024,"url":"https:\/\/cloudproinc.com.au\/wp-content\/uploads\/2025\/08\/Guardrails.png","type":"image\/png"}],"author":"CPI Staff","twitter_card":"summary_large_image","twitter_misc":{"Written by":"CPI Staff","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/#article","isPartOf":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/"},"author":{"name":"CPI Staff","@id":"https:\/\/cloudproinc.com.au\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e"},"headline":"Building Guardrails in the OpenAI Agent SDK","datePublished":"2025-08-19T23:07:31+00:00","dateModified":"2025-08-19T23:07:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/"},"wordCount":817,"commentCount":0,"publisher":{"@id":"https:\/\/cloudproinc.com.au\/#organization"},"image":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/08\/Guardrails.png","articleSection":["AI","AI Agents","Blog","OpenAI","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/#respond"]}],"accessibilityFeature":["tableOfContents"]},{"@type":"WebPage","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/","url":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/","name":"Building Guardrails in the OpenAI Agent SDK - CPI Consulting","isPartOf":{"@id":"https:\/\/cloudproinc.com.au\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/#primaryimage"},"image":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2025\/08\/Guardrails.png","datePublished":"2025-08-19T23:07:31+00:00","dateModified":"2025-08-19T23:07:34+00:00","description":"Learn about building guardrails in the OpenAI Agent SDK to protect agents from misuse and ensure safe operations.","breadcrumb":{"@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/#primaryimage","url":"\/wp-content\/uploads\/2025\/08\/Guardrails.png","contentUrl":"\/wp-content\/uploads\/2025\/08\/Guardrails.png","width":1536,"height":1024},{"@type":"BreadcrumbList","@id":"https:\/\/www.cloudproinc.com.au\/index.php\/2025\/08\/20\/building-guardrails-in-the-openai-agent-sdk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudproinc.com.au\/"},{"@type":"ListItem","position":2,"name":"Building Guardrails in the OpenAI Agent SDK"}]},{"@type":"WebSite","@id":"https:\/\/cloudproinc.com.au\/#website","url":"https:\/\/cloudproinc.com.au\/","name":"Cloud Pro Inc - CPI Consulting Pty Ltd","description":"Cloud, AI &amp; Cybersecurity Consulting | Melbourne","publisher":{"@id":"https:\/\/cloudproinc.com.au\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudproinc.com.au\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudproinc.com.au\/#organization","name":"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd","url":"https:\/\/cloudproinc.com.au\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudproinc.com.au\/#\/schema\/logo\/image\/","url":"\/wp-content\/uploads\/2022\/01\/favfinalfile.png","contentUrl":"\/wp-content\/uploads\/2022\/01\/favfinalfile.png","width":500,"height":500,"caption":"Cloud Pro Inc - Cloud Pro Inc - CPI Consulting Pty Ltd"},"image":{"@id":"https:\/\/cloudproinc.com.au\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/cloudproinc.com.au\/#\/schema\/person\/192eeeb0ce91062126ce3822ae88fe6e","name":"CPI Staff","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2d96eeb53b791d92c8c50dd667e3beec92c93253bb6ff21c02cfa8ca73665c70?s=96&d=mm&r=g","caption":"CPI Staff"},"sameAs":["http:\/\/www.cloudproinc.com.au"],"url":"https:\/\/cloudproinc.com.au\/index.php\/author\/cpiadmin\/"}]}},"jetpack_featured_media_url":"\/wp-content\/uploads\/2025\/08\/Guardrails.png","jetpack-related-posts":[{"id":53640,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/08\/18\/build-a-multi-agent-assistant-in-python-with-the-openai-agents-sdk\/","url_meta":{"origin":53658,"position":0},"title":"Build a Multi-Agent Assistant in Python with the OpenAI Agents SDK","author":"CPI Staff","date":"August 18, 2025","format":false,"excerpt":"This post \"Build a Multi-Agent Assistant in Python with the OpenAI Agents SDK\" shows how to build an AI agent that can (a) generate secure passwords, (b) tell the current time, and (c) hand off coding questions to a Python-tutor sub-agent. Along the way, we\u2019ll cover what the Agents SDK\u2026","rel":"","context":"In &quot;AI Agents&quot;","block_context":{"text":"AI Agents","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/ai-agents\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/08\/build-a-multi-agent-assistant-in-python-with-the-openai-agen-1.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/08\/build-a-multi-agent-assistant-in-python-with-the-openai-agen-1.png 1x, \/wp-content\/uploads\/2025\/08\/build-a-multi-agent-assistant-in-python-with-the-openai-agen-1.png 1.5x, \/wp-content\/uploads\/2025\/08\/build-a-multi-agent-assistant-in-python-with-the-openai-agen-1.png 2x, \/wp-content\/uploads\/2025\/08\/build-a-multi-agent-assistant-in-python-with-the-openai-agen-1.png 3x, \/wp-content\/uploads\/2025\/08\/build-a-multi-agent-assistant-in-python-with-the-openai-agen-1.png 4x"},"classes":[]},{"id":53667,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/08\/21\/build-git-mcp-server-with-the-openai-agents-sdk\/","url_meta":{"origin":53658,"position":1},"title":"Build Git MCP Server with the OpenAI Agents SDK","author":"CPI Staff","date":"August 21, 2025","format":false,"excerpt":"This OpenAI post \"Build Git MCP Server with the OpenAI Agents SDK\" shows how to implement an MCP Server into an agent. Table of contentsWhat\u2019s the Git MCP server?Why MCP with the Agents SDK?Packages you needComponents in the codeTypes of MCP servers (transports)How the run worksScoping Git operations to a\u2026","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/08\/build-git-mcp-server-with-the-openai-agents-sdk.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/08\/build-git-mcp-server-with-the-openai-agents-sdk.png 1x, \/wp-content\/uploads\/2025\/08\/build-git-mcp-server-with-the-openai-agents-sdk.png 1.5x, \/wp-content\/uploads\/2025\/08\/build-git-mcp-server-with-the-openai-agents-sdk.png 2x, \/wp-content\/uploads\/2025\/08\/build-git-mcp-server-with-the-openai-agents-sdk.png 3x, \/wp-content\/uploads\/2025\/08\/build-git-mcp-server-with-the-openai-agents-sdk.png 4x"},"classes":[]},{"id":56954,"url":"https:\/\/cloudproinc.com.au\/index.php\/2026\/02\/04\/openai-codex-app-for-faster-secure-code\/","url_meta":{"origin":53658,"position":2},"title":"OpenAI Codex App for Faster Secure Code","author":"CPI Staff","date":"February 4, 2026","format":false,"excerpt":"Learn how the OpenAI Codex app speeds up delivery without sacrificing security. Set up safe sandboxes, run parallel agent tasks, and automate routine engineering work with clear review gates.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2026\/02\/post-7.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2026\/02\/post-7.png 1x, \/wp-content\/uploads\/2026\/02\/post-7.png 1.5x, \/wp-content\/uploads\/2026\/02\/post-7.png 2x, \/wp-content\/uploads\/2026\/02\/post-7.png 3x, \/wp-content\/uploads\/2026\/02\/post-7.png 4x"},"classes":[]},{"id":56780,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/11\/10\/security-best-practices-for-azure-ai-services\/","url_meta":{"origin":53658,"position":3},"title":"Security Best Practices for Azure AI Services","author":"CPI Staff","date":"November 10, 2025","format":false,"excerpt":"Practical, step-by-step guidance to secure Azure AI services end to end\u2014identity, networks, data, prompts, and monitoring\u2014so your teams can innovate confidently without exposing your organisation.","rel":"","context":"In &quot;Azure AI Services&quot;","block_context":{"text":"Azure AI Services","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/azure-ai-services\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/11\/security-best-practices-for-azure-ai-services-in-practice.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/11\/security-best-practices-for-azure-ai-services-in-practice.png 1x, \/wp-content\/uploads\/2025\/11\/security-best-practices-for-azure-ai-services-in-practice.png 1.5x, \/wp-content\/uploads\/2025\/11\/security-best-practices-for-azure-ai-services-in-practice.png 2x, \/wp-content\/uploads\/2025\/11\/security-best-practices-for-azure-ai-services-in-practice.png 3x, \/wp-content\/uploads\/2025\/11\/security-best-practices-for-azure-ai-services-in-practice.png 4x"},"classes":[]},{"id":57066,"url":"https:\/\/cloudproinc.com.au\/index.php\/2026\/02\/20\/why-claude-code-is-suddenly-on-every-cios-radar-in-2026\/","url_meta":{"origin":53658,"position":4},"title":"Why Claude Code Is Suddenly on Every CIO\u2019s Radar in 2026","author":"CPI Staff","date":"February 20, 2026","format":false,"excerpt":"Claude Code is changing how teams build and maintain software by turning plain-English requests into real, testable code changes. Here\u2019s what CIOs should do next to adopt it safely and measure ROI.","rel":"","context":"In &quot;Blog&quot;","block_context":{"text":"Blog","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/blog\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2026\/02\/post-31.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2026\/02\/post-31.png 1x, \/wp-content\/uploads\/2026\/02\/post-31.png 1.5x, \/wp-content\/uploads\/2026\/02\/post-31.png 2x, \/wp-content\/uploads\/2026\/02\/post-31.png 3x, \/wp-content\/uploads\/2026\/02\/post-31.png 4x"},"classes":[]},{"id":53555,"url":"https:\/\/cloudproinc.com.au\/index.php\/2025\/07\/29\/counting-tokens-using-the-openai-python-sdk\/","url_meta":{"origin":53658,"position":5},"title":"Counting Tokens Using the OpenAI Python SDK","author":"CPI Staff","date":"July 29, 2025","format":false,"excerpt":"This post provides a comprehensive guide on counting tokens using the OpenAI Python SDK, covering Python virtual environments, managing your OpenAI API key securely, and the role of the requirements.txt file. In the world of Large Language Models (LLMs) and Artificial Intelligence (AI), the term \"token\" frequently arises. Tokens are\u2026","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/cloudproinc.com.au\/index.php\/category\/ai\/"},"img":{"alt_text":"","src":"\/wp-content\/uploads\/2025\/07\/image-23.png","width":350,"height":200,"srcset":"\/wp-content\/uploads\/2025\/07\/image-23.png 1x, \/wp-content\/uploads\/2025\/07\/image-23.png 1.5x, \/wp-content\/uploads\/2025\/07\/image-23.png 2x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/53658","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=53658"}],"version-history":[{"count":2,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/53658\/revisions"}],"predecessor-version":[{"id":53661,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/posts\/53658\/revisions\/53661"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/media\/53659"}],"wp:attachment":[{"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=53658"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=53658"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudproinc.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=53658"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}