Production AI Security Checklist

Ma Mahalakshmi V Updated 19 Sep 2026
6 min read ·Lesson 163 of 224

Security checklist for production OpenAI SDK applications

Unit 14, Lesson 4 covered a general deployment checklist, where secrets management appeared as a single line item ("secrets come from the hosting platform's secrets management") among broader operational concerns like health checks, scaling, and rollout strategy. This checklist is narrower and deeper: it consolidates every security- and privacy-specific practice from this unit into one reference you can walk through before shipping an OpenAI SDK application to production, organized by the same categories this unit covered.

Secrets management

  1. Every API key is scoped to a specific project and environment (Lesson 1) — no single key is shared across development, staging, and production.
  2. No API key, or any other secret, appears anywhere in source code or commit history (Lesson 2). A secret scanner runs as a pre-commit hook and in CI.
  3. Production and staging secrets come from a dedicated secret manager, not from a .env file on the server (Lesson 3). .env files are used only for local development and are listed in .gitignore.
  4. No secret is baked into a container image via ARG or ENV in a Dockerfile; all secrets are injected at container runtime (Lesson 3).
  5. A key-rotation process exists and has been exercised at least once — rotating a key should require a configuration change, not a code change or redeploy of application logic (Lesson 1).

Prompt and content safety

  1. Every prompt that incorporates externally sourced content (web pages, documents, tool outputs, other users' data) wraps that content in explicit, labeled delimiters and states clearly, in the trusted developer/system message, that the content is data and not instructions (Lessons 4 and 5).
  2. No untrusted content is ever concatenated directly into the system/developer message. It is confined to clearly delimited sections of user-role or tool-role content.
  3. Any model call that processes untrusted content has no access to consequential tools unless a specific, reviewed exception has been made, in which case additional validation and authorization checks (items 11-15 below) apply (Lesson 4).
  4. Workflows that both process untrusted content and need to take action are split into separate steps, so the step with tool access does not also hold the raw untrusted content in its context (Lesson 4).
  5. Delimiter tags used for untrusted content are not trivially guessable static strings that an attacker could replicate to attempt to escape the intended boundary (Lesson 5).

Tool execution

  1. Every tool has an explicit argument-validation function that runs before execution, checking types, allow-listed values, and numeric ranges — schema conformance alone is not treated as sufficient (Lesson 6).
  2. Any argument that constructs a file path, URL, or query is checked structurally (for example, resolving a path and confirming it remains inside an allowed directory) rather than relying on blocklisting suspicious substrings alone (Lesson 6).
  3. Business-rule limits (maximum discount, maximum transfer amount, rate limits) are enforced in code as hard ceilings, independent of anything the model is told in a prompt (Lesson 6).
  4. Every tool has an explicit, fail-closed authorization check confirming the authenticated user's role permits that specific tool, before the tool executes (Lesson 9).
  5. Tools acting on a specific resource (an order, an account, a record) enforce resource-level authorization, not just role-level authorization (Lesson 9).
  6. High-risk, hard-to-reverse actions require explicit human confirmation before execution, independent of automated validation and authorization (Lesson 9).

Data privacy

  1. Only the fields a given task actually requires are included in a prompt — full customer or user records are not sent when a subset of fields would serve the same purpose (Lesson 7).
  2. Known PII patterns (emails, phone numbers, government IDs, payment details) are redacted before constructing a prompt, wherever the task does not specifically require the model to see the raw value (Lesson 7).
  3. Structured output schemas are used where applicable to prevent the model from echoing sensitive values back into free-form output (Lesson 7).
  4. A documented decision exists for how long conversation and request data is retained, consistent with applicable data-protection requirements for your users' jurisdictions.

Logging and monitoring

  1. Production log statements never include full raw prompts or completions by default — only metadata (request IDs, token counts, latency, status codes) is logged (Lesson 8).
  2. A redacting log filter is attached to production loggers as a safety net against secrets or PII patterns appearing in log messages incidentally (Lesson 8).
  3. Verbose, full-content debug logging is explicitly gated to non-production environments and never shipped to a shared or remote log aggregator (Lesson 8).
  4. Moderation flags and safety-relevant events are logged as categorized metadata, not as the full flagged content itself (Lesson 8, building on Unit 12, Lesson 7).
  5. Access to logs and log-aggregation tooling is restricted to those who need it, with the same level of scrutiny applied to a database containing equivalent data.

A pre-deployment self-check

The checklist above is a review process, but a few of its items can be partially automated. The following script sketches a self-check that a CI pipeline could run before allowing a deployment, combining ideas from Lessons 2 and 6 of this unit into one gate.

import re


def scan_for_hardcoded_secrets(source_files: dict[str, str]) -> list[str]:
    """Returns filenames containing strings that look like API keys."""
    pattern = re.compile(r"sk-[A-Za-z0-9-]{16,}")
    return [name for name, content in source_files.items() if pattern.search(content)]


def check_tools_have_permissions(
    tool_names: list[str], permission_map: dict[str, set]
) -> list[str]:
    """Returns tool names that have no entry in the permission map."""
    return [name for name in tool_names if name not in permission_map]


def run_predeploy_security_checks(
    source_files: dict[str, str],
    tool_names: list[str],
    permission_map: dict[str, set],
) -> list[str]:
    """
    Runs a small set of automatable security checks and returns a list
    of human-readable failure messages. An empty list means these
    specific automated checks passed (the rest of the checklist still
    requires manual review).
    """
    failures = []

    leaked = scan_for_hardcoded_secrets(source_files)
    if leaked:
        failures.append(f"Hardcoded secret pattern found in: {', '.join(leaked)}")

    unprotected = check_tools_have_permissions(tool_names, permission_map)
    if unprotected:
        failures.append(f"Tools with no permission entry: {', '.join(unprotected)}")

    return failures
def test_predeploy_check_catches_hardcoded_key():
    source_files = {"config.py": 'API_KEY = "sk-proj-abcdefghijklmnopqrstuvwxyz"'}
    failures = run_predeploy_security_checks(
        source_files, tool_names=[], permission_map={}
    )
    assert any("Hardcoded secret" in f for f in failures)
    print("PASS: pre-deploy check flags a hardcoded API key")


def test_predeploy_check_catches_unprotected_tool():
    failures = run_predeploy_security_checks(
        source_files={},
        tool_names=["issue_refund", "lookup_order_status"],
        permission_map={"lookup_order_status": {"customer"}},
    )
    assert any("issue_refund" in f for f in failures)
    print("PASS: pre-deploy check flags a tool with no permission entry")


def test_predeploy_check_passes_clean_project():
    failures = run_predeploy_security_checks(
        source_files={"app.py": "import os\nkey = os.environ['OPENAI_API_KEY']"},
        tool_names=["lookup_order_status"],
        permission_map={"lookup_order_status": {"customer"}},
    )
    assert failures == []
    print("PASS: pre-deploy check produces no failures for a properly configured project")


test_predeploy_check_catches_hardcoded_key()
test_predeploy_check_catches_unprotected_tool()
test_predeploy_check_passes_clean_project()

This kind of automated gate catches a narrow but real slice of the full checklist — an obviously hardcoded key, or a tool that was added without a corresponding permissions entry. It is a useful complement to, not a replacement for, the manual review implied by the rest of the checklist above: prompt structure, data minimization decisions, and human-confirmation requirements for high-risk actions are policy and architecture choices that a script cannot fully verify on its own.

Using this checklist

Treat the 25 items above as a review to walk through deliberately before a production launch and periodically afterward — not as a one-time gate that, once passed, never needs revisiting. New tools added to an existing application need new entries in the permission map (item 14) and their own validation logic (item 11); new integrations that pull in external content need the same trust-separation review (items 6-10) that the original ones received; and a key that has never been rotated (item 5) becomes a larger liability the longer it goes unrotated, even if nothing about the surrounding code has changed at all.

0 Comments

Reviewed before they appear

No comments yet.

OpenAI SDK
Introduction to the OpenAI SDK Setting Up Python Creating an API Key Your First Call — client.responses.create() and response.output_text Understanding Billing, Credits, and What a Request Costs Why Responses Replaced Chat Completions Anatomy of a Request: model, input, and instructions Anatomy of a Response: The Typed output Array, Not Just Text Roles: User, Assistant, and Developer/System Choosing a Model, and Reading the Models Page Instead of Memorizing Names Instructions vs. Input Writing Prompts That Get Consistent Results Few-Shot Examples Reasoning Models and the reasoning Parameter Debugging a Prompt That Misbehaves Why Streaming Matters for User Experience stream=True and Iterating Over Events Handling the Event Types You Actually Care About Background Mode for Long-Running Jobs Project — Add Live Streaming to Your Chatbot The Problem With Parsing Free Text JSON Schema and Strict Mode Pydantic Models With the SDK's Parse Helpers Handling Refusals and Validation Failures Project — A Resume-to-JSON Extractor Working With input_image input_file, PDFs, and the Files API Image Generation Speech-to-Text and Text-to-Speech Project: A PDF Question-Answering Script What Function Calling Is Defining a Tool Schema The Full Loop Multiple Tools Errors, Timeouts, and Untrusted Arguments Project: A Weather Assistant Web Search File Search and Vector Stores Code Interpreter Remote MCP Servers and Connectors Project: A Research Assistant What an Embedding Is, Without the Maths Generating and Storing Embeddings Similarity Search From Scratch Hosted Vector Stores vs. Rolling Your Own A Small RAG App Over a Folder of Notes Agents vs. a Single API Call — When You Need One pip install openai Giving Agents Tools Handoffs and Multi-Agent Triage Guardrails and Approvals Tracing and Observing What Your Agent Did A Multi-Agent Support Desk Error Codes and What Each One Means Retries, Timeouts, and Backoff Rate Limits and Spend Limits Prompt Caching and Cost Optimisation The Batch API for Bulk Work Async Clients and Concurrency Moderation and Safety Best Practices Designing the App Backend With FastAPI Streaming to a Simple Frontend Deploying and a Cost/Safety Checklist Why Web Search Is Useful for Current Information Using the Web Search Tool with the Responses API Configuring Search Behavior for Application Use Cases Understanding Citations and Source Attribution Where to Go Next Building a Research Assistant with Web Search Combining Web Search with Structured Outputs Handling Conflicting or Low-Quality Web Sources Reducing Unsupported Claims with Grounded Generation Testing Freshness-Sensitive AI Answers Production Considerations for Web-Grounded Applications Understanding File Search and Retrieval-Augmented Generation Creating and Organizing Vector Stores Uploading Documents for Retrieval Connecting Vector Stores to Responses API Requests Designing Document Metadata and Filtering Strategies Building a PDF Question-Answering Application Improving Retrieval Quality With Better Document Preparation Handling Missing Evidence and Retrieval Failures Combining File Search With Web Search Building a Production Knowledge-Base Assistant What the Code Interpreter Tool Is Designed For Running Python-Based Analysis Through the OpenAI SDK Uploading Datasets for Analysis Analyzing CSV and Spreadsheet Data Generating Charts and Data Summaries Handling Generated Files and Downloadable Artifacts Building a Data-Analysis Assistant Combining Code Execution with Structured Outputs Validating Generated Calculations and Results Security and Sandbox Considerations for Code Execution Understanding Multimodal Input with the OpenAI SDK Sending Images to a Model Image Analysis from URLs and Uploaded Files Extracting Text and Information from Screenshots Building an Image-Question-Answering Application Combining Image Input with Structured Output Analyzing Multiple Images in One Request Handling Image Quality and Input Limitations Designing Multimodal Prompts for Reliable Results Building a Practical Vision-Powered Python Application Understanding Speech-to-Text and Text-to-Speech Workflows Transcribing Audio with the OpenAI SDK Working with Uploaded Audio Files Handling Timestamps and Transcription Metadata Building a Meeting Transcription Workflow Generating Spoken Responses from Text Handling Long Audio and Processing Failures Combining Audio with Text and Tool Calling Building an End-to-End Python Voice Application What Embeddings Are and When to Use Them Generating Embeddings With the OpenAI API Preparing Text for Embedding Comparing Vectors With Cosine Similarity Building a Simple Semantic Search Engine in Python Storing Embeddings in a Database Metadata Filtering for Semantic Search Chunking Strategies for Better Retrieval Evaluating Semantic Search Quality Building a Document Similarity Application When Batch Processing Makes Sense Designing Large-Volume AI Processing Pipelines Using Asynchronous Python with the OpenAI SDK Running Concurrent Requests Safely Controlling Concurrency and Avoiding Rate Limits Tracking Batch Job Progress Handling Partial Failures in Bulk Workloads Retrying Failed Items Without Duplicating Successful Work Designing Resumable AI Processing Jobs Building a Production Batch-Processing Pipeline Batch Processing Makes Sense Large-Scale AI Processing Pipelines Async Python with OpenAI SDK Safe Concurrent Requests Concurrency & Rate Limits Batch Progress Tracking Partial Failure Handling Safe Retry Handling Resumable AI Jobs Production Batch Pipeline System–User Data Separation Reusable App Instructions Prompt Templates & Variables Extraction & Classification Prompts Summarization & Transformation Prompts Explicit Output Requirements Prompt Version Management Prompt Testing & Evaluation Reusable Python Prompt Library API Key Security Secure API Key Storage Secure Secret Management Prompt Injection Prevention Trusted vs. Untrusted Content Tool Argument Validation Sensitive Data Handling Secure Logging AI Action Authorization Production AI Security Checklist Why AI Applications Need Evaluation Beyond Unit Tests Unit Testing OpenAI SDK Integration Code Mocking API Responses in Python Tests Testing Structured Outputs Against Schemas Testing Tool-Calling Workflows Building a Small Evaluation Dataset Measuring Accuracy, Consistency, and Failure Rates Regression Testing Prompts and Model Changes Human Evaluation Versus Automated Evaluation Creating a Repeatable Evaluation Pipeline AI Request Monitoring Token Cost Management Usage Metrics Design Reducing Model Calls Prompt & Context Optimization Model Selection & Optimization AI Caching Strategies Interactive Latency Optimization Usage Dashboards & Budget Alerts Performance & Cost Checklist Every API Call Starts Fresh Fixing API Statelessness Server-Side Conversation Memory Limits of Response Chaining What We're Building Conversation Memory Challenges Preparing an OpenAI SDK Application for Deployment Environment-Specific Configuration for Development and Production Deploying a Python AI Service with Docker Container Health Checks and Startup Configuration Managing Secrets in Cloud Deployments Background Workers for Long-Running AI Tasks Queues and Asynchronous Job Architectures Scaling AI Workloads Horizontally Monitoring Production Incidents and Failures Production Deployment Checklist for OpenAI SDK Applications Reusable OpenAI Service Classes AI Client Dependency Injection Typed AI Responses Python Configuration Management AI Request Decorators Centralized AI Error Handling Clean SDK Abstractions Reusable OpenAI Utilities Internal AI Python Libraries SDK Integration Maintenance Production AI Chatbot Document Q&A System Web Research Assistant Customer Support Agent AI Data Analysis Assistant Image Analysis App Meeting Transcription & Summary Semantic Document Search Multi-Tool AI Agent Production OpenAI SDK App Why "It Looked Fine When I Tested It" Isn't Enough Timing Note Status Note Pre-Decision Status Note Current Availability Note
Ask about this post
AI Ask about this post

Ask questions about Production AI Security Checklist and get answers drawn from it.

Signed-in readers only.