← Blog

Validate Azure OpenAI Batch Input Files Before Upload

Parminder Singh
Parminder Singh··6 min read
Summarize with AI

Azure OpenAI Batch validates an uploaded JSONL file before processing, but production clients need an earlier gate. This guide checks line parsing, unique custom IDs, one endpoint and deployment, request body policy, file identity, upload state, and provider validation without confusing a processed upload with an accepted batch.

Platform & Architectureai-securityllm-securitypolicy-enforcementdevsecopsauditarchitecture
Validate Azure OpenAI Batch Input Files Before Upload

Azure OpenAI Batch reads a JSONL file as a collection of model requests. One malformed line, duplicate custom_id, mixed URL, or mismatched deployment can move the job into failed during provider validation. A client-side gate should reject those defects before upload, bind the exact file bytes to an approved manifest, and then wait for Azure's own validation result. The two gates answer different questions and both belong in the release record.

TL;DR

  • Parse every JSONL line independently and reject blank or structurally invalid requests before upload.
  • Require one approved endpoint family and deployment across the file, with a unique custom ID for every row.
  • Bind the final byte hash, row count, identity, and data class to an immutable manifest, along with route approval.
  • Treat file upload status and batch validation status as separate provider checkpoints.

Azure validates the submitted file

Microsoft's Azure OpenAI Batch guide describes a provider validation phase before processing begins. Its status sequence distinguishes validating, failed, in_progress, finalizing, and terminal outcomes. A successfully uploaded file can therefore fail after the batch object is created.

Microsoft also publishes named validation errors. They include invalid JSON lines, duplicate custom IDs, empty files, URL mismatch, unknown deployment names, deployment mismatch across rows, invalid request schemas, modified blob input, and inaccessible blob input. Those errors are useful acceptance fixtures for your preflight gate.

Preflight returns a specific failure while the file remains local, before prompt content enters provider storage and before an asynchronous job needs cleanup. Azure validation remains authoritative for what the service accepts.

My blunt opinion is that "the provider will validate it" is a release-process bug.

Parse JSONL as bytes, lines, and requests

Freeze the final file bytes before validation. Record the encoding, byte length, digest, and newline convention. Then read one physical line at a time. Each non-empty line must parse into exactly one JSON object. Reject a byte-order mark at the start, trailing non-whitespace after an object, blank lines, invalid UTF-8, and a final partial line produced by an interrupted writer.

Next, validate the request envelope for each row. It needs a unique custom_id, the expected HTTP method, an allowed relative URL, and a body matching the chosen API surface. Apply exact type checks before policy checks. A numeric model field or object-shaped method should fail as schema defects rather than drift into string coercion.

Build the identifier set before upload and compare its cardinality with the parsed row count. The OpenAI Batch custom ID correlation guide explains the manifest relationship carried into result reconciliation. Azure's duplicate_custom_id error gives you the provider-side fixture for the same invariant.

On a terminal screen, print the first failing line number and a red reason code. Include its custom_id when available. Keep prompt text out of that diagnostic. Give the operator the coordinate and cause while regulated content stays in its controlled store.

One file needs one coherent destination

Microsoft documents url_mismatch when request URLs differ inside the input or conflict with the expected endpoint. It documents model_mismatch when request bodies name different deployments. Preflight should canonicalize both values and compare them across all rows.

Allow only the method and relative endpoint supported by the approved batch profile, preserving every meaningful path component. Reject absolute URLs instead of trusting their suffix, and reject query parameters unless the profile names them. Resolve the body model field to the Azure deployment name recorded in control-plane inventory, then compare every row with that manifest entry.

The route profile should also include Azure resource hostname, deployment SKU, API family, allowed identities, prompt data classes, owner, approval time, and policy version. Azure inventory and release automation supply those control-plane facts; the input file supplies request content.

The Azure OpenAI gateway patterns guide covers resource and deployment routing. Batch validation adds file-wide invariants before that destination processes any row.

Validate request bodies against policy

After schema validation, inspect the fields that change data exposure or model behavior. Set explicit allowlists for message roles, content part types, image inputs, tools, structured-output settings, and output limits used by the workload. Reject unknown top-level fields until the profile has been reviewed for the active API version.

Run data classification on each request body and aggregate the highest sensitivity into the file manifest. A single restricted row makes the file restricted for storage and transport. It also restricts reviewer access. Keep credentials and storage signatures, including bearer tokens, outside the JSONL rows. They belong on the authenticated upload or submission exchange.

Use a canonical request fingerprint per row and a separate digest for the complete file. The row fingerprint detects mutation behind a reused custom_id. The file digest proves which ordered byte sequence received approval. The AI gateway file upload scanning guide covers malware and file-type controls; this gate focuses on the JSONL request semantics inside an Azure Batch input.

Microsoft's data privacy documentation treats uploaded Batch data as customer content processed by the service. Classification and retention approval should therefore happen before upload, while the content remains local.

Upload state and batch state require separate evidence

The Files API returns its own file object and status. Microsoft shows a file reaching processed before the client creates a batch with its file ID. Record the provider file ID, returned byte count, purpose, creation time, expiry when present, and status. Compare the returned byte count with the local manifest, but keep the local digest as the stronger identity control.

Create the batch only after the upload reaches the documented usable state. Bind the input file ID, Azure resource, deployment profile, submitting workload identity, and local manifest digest in the creation record. Then poll the batch object and preserve its validation transition.

Batch validation checks the deployment and URL after upload. A local preflight pass proves conformance to your policy version.

For Blob Storage input, protect against post-approval mutation. Microsoft's batch errors include input_modified and input_no_permissions. Use immutable or version-addressed blobs where your platform supports them, record the blob version and digest, and test permission loss before production.

Acceptance fixtures should reproduce Azure error classes

Create a compact fixture for each named failure you intend to intercept:

  • Corrupt one JSON line and append a partial final object.
  • Duplicate a custom_id while changing the body.
  • Mix chat-completions and Responses URLs in one file.
  • Change one row to another deployment name.
  • Remove all rows and submit an empty file fixture.
  • Add a body field with the wrong type or an unapproved content part.
  • Mutate a versioned blob after approval in a destructive test account.
  • Remove the Azure resource identity's read permission from the test container.

The destructive storage cases should reach Azure only inside an isolated acceptance environment and produce the expected provider error. Preserve reason codes at both layers so operators know which control made the decision.

The AI policy engine guide covers versioned policy decisions. Attach that policy version to the file manifest and every submission attempt.

DeepInspect

DeepInspect can inspect authenticated HTTP file-upload and batch-creation exchanges deliberately routed through its proxy. It can enforce the approved Azure resource and route, then apply identity and data-class policy to supplied context. It records the decision with the manifest digest before forwarding.

The batch client remains responsible for parsing JSONL, validating every body, generating unique custom IDs, freezing file bytes, managing Blob Storage, polling Azure status, and reconciling results. Azure remains authoritative for its upload and batch validation states. Direct storage or provider calls outside the routed HTTP path remain outside DeepInspect visibility.

Book a technical deep dive at deepinspect.ai.

Frequently asked questions

Does a processed file status mean the batch input is valid?

The file object and batch object have separate lifecycles. Create the batch after the upload is processed, then wait for the batch to leave validating. A provider failed state needs its errors preserved with the manifest.

Should the validator rewrite malformed lines?

Reject the artifact and regenerate the complete file. Silent repair can change request intent and line ordering. It can also change the digest that received approval. Report a line coordinate and reason code while keeping the original bytes for controlled diagnosis.

Can one input file contain several Azure deployments?

Microsoft documents model_mismatch when deployment names differ within the file. Keep one coherent deployment and route profile per file. Split mixed work into separately approved files and batches.

Where should secrets appear in the JSONL file?

Keep every secret outside the JSONL file. Authenticate the upload and batch creation exchanges using the approved workload identity or credential path. Limit each row to model input and parameters. Send bearer tokens or storage signatures only on their approved authentication path.