← Blog

Duplicate JSON Member Policy for LLM APIs

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

Duplicate JSON members create ambiguous LLM API requests because parsers can keep the first value, keep the last value, reject the object, or expose every occurrence. This guide defines a fail-closed duplicate-member policy at the authenticated HTTP boundary, covers raw-body inspection and nested objects, and gives release tests for model, tool, streaming, and policy-relevant fields.

Platform & Architectureai-securityllm-securityapi-securityjsonzero-trustpolicy-enforcement
Duplicate JSON Member Policy for LLM APIs

A JSON object can carry the same member name twice. An LLM request might therefore contain two model members or two stream flags. It might also contain two tool definitions under one object. If the gateway keeps the first value while the model adapter keeps the last, policy evaluates one request and the provider receives another.

Put the raw request beside the parsed object on screen. In the left terminal, model appears twice inside the same pair of braces. In the right terminal, the object contains one value because the parser silently discarded the other occurrence. That missing line is the policy problem.

TL;DR

  • Reject duplicate member names before route and model policy runs. Apply the same rejection before tool or data policy runs.
  • Compare names after JSON escape processing, so equivalent escaped and unescaped names count as duplicates.
  • Inspect the original request body with a duplicate-aware parser and retain a bounded, redacted reason record.
  • Test nested objects, tool arguments, streaming requests, and parser upgrades. Test every adapter that reserializes the body.

JSON permits syntax that receivers interpret differently

RFC 8259 Section 4 says names within a JSON object should be unique. It then records the interoperability failure created by duplicates: many implementations report the last pair. Some report an error, while others expose all pairs. The specification calls receiver behavior unpredictable when names repeat.

The grammar still permits another member after a comma, including one with an already used name. A request can therefore be valid JSON syntax while remaining unsafe for a protocol that needs one stable meaning. Syntax acceptance and policy acceptance are separate gates.

I-JSON Section 2.3 sets a stricter profile. I-JSON messages must exclude duplicate member names. It defines duplication after escaped characters have been processed, using identical Unicode character sequences. A policy should catch both visibly repeated names and equivalent names expressed with JSON escapes.

I would reject duplicates across the entire LLM request, rather than maintain a fragile list of sensitive fields. A duplicate that looks harmless today can become a routing or tool-control input after an adapter release.

Parser disagreement changes the authorized request

An authenticated caller sends bytes over HTTP. The gateway verifies identity, parses the body, applies route policy, and forwards a provider-specific representation. Each parser or serializer in that chain can choose a different duplicate-member behavior.

Consider a body with "model":"approved-small" followed by "model":"restricted-large". A first-wins policy parser can authorize the smaller model. A last-wins provider client can send the larger one. Reversing the values creates the same class of mismatch under the opposite parser behavior.

The risk extends beyond model. Duplicate stream values can change response handling. Repeated limits can alter cost controls. Tool names, tool arguments, response formats, tenant hints, safety settings, and provider options can all influence the request that leaves the gateway. The per-route AI policies guide explains why those inputs belong to a request-time decision rather than a broad authenticated session.

Nested objects need the same rule. A unique top-level tools member can contain a duplicate name or a repeated argument key several levels down. Arrays may contain repeated values by design, so the detector should track member names separately for each object instead of treating repetition anywhere in the document as an error.

Detection must happen before ordinary object construction

A conventional object parser often loses duplicate evidence while constructing an in-memory map. By the time policy code receives the object, only one value remains. Re-serializing that object cannot recover the discarded occurrence.

Use a parser mode that reports each member event before insertion, or run a streaming duplicate detector over the original UTF-8 body. Maintain a set of decoded member names for each open object. When a decoded name already exists in that object's set, stop processing and return the documented client error. Apply normal depth and size limits at the same stage.

Keep this detector on the exact bytes accepted by the LLM route. Decompression and character decoding need one defined order. Media-type handling must follow that order. If an ingress proxy transforms the body, the component making the policy decision should inspect the resulting authoritative representation and preserve enough transport metadata to explain the transformation. The LLM API authority validation guide provides the matching rule for destination inputs.

Avoid a cleanup mode that silently chooses a winner. Normalization hides a malformed request and can make signatures, hashes, application logs, or downstream parsers describe different content. A stable rejection gives the client one corrective action: send each object member once.

Denial behavior needs a stable contract

Return a client error before contacting the model endpoint. The public response can use a type such as duplicate_json_member and identify the occurrence with an opaque correlation ID. Exposing the repeated member name may be acceptable for a developer API, but it should follow the route's disclosure policy because tool arguments and extension fields can contain sensitive names.

The protected decision record should include the authenticated principal or workload, route, content type, body size, parser version, object path under the approved redaction policy, normalized repeated name when safe, decision, and correlation ID. Avoid storing the full raw prompt merely to prove that rejection worked. A keyed body digest or retained test fixture can support engineering diagnosis without copying production content into logs.

Keep the HTTP response distinct from authentication failures. Duplicate JSON arrives after the caller has presented a request body; it does not turn a valid identity into an invalid credential. The LLM API authentication challenges guide describes the separate 401 and 403 contract.

Release tests must cross every parser boundary

Run the fixtures through the deployed load balancer, gateway, policy parser, provider adapter, and streaming path. A unit test for one JSON library leaves the disagreement risk intact.

Include these cases:

  • A top-level model member appears twice with allowed and denied values in both orders.
  • A repeated stream flag uses true and false in both orders.
  • A nested tool argument repeats a name, while the same name in two different objects remains valid.
  • One member name uses a JSON escape and the other uses the equivalent decoded character sequence.
  • Empty objects and arrays pass, and repeated array values remain valid.
  • A compressed request follows the documented decoding path before duplicate detection.
  • Oversized or excessively deep input reaches its own bounded denial without exhausting memory.
  • Each supported provider adapter receives no outbound request after a duplicate is found.

Capture the client status, stable error type, duplicate detector version, policy decision, outbound-attempt count, and redacted audit event. Repeat the suite after parser, framework, proxy, or provider-SDK upgrades. The release fails if any path forwards the body or if two components disagree about acceptance.

DeepInspect

DeepInspect can apply a duplicate-member decision to authenticated user or agent requests deliberately routed through its HTTP path to an LLM endpoint. The decision can run before model, tool, route, or data policy consumes a parsed body, then produce a per-request allow or deny record with bounded redaction.

Application frameworks still own body handling before traffic reaches that route, and provider adapters own the representation they create downstream. Direct provider calls and local model execution sit outside this HTTP enforcement path. STDIO tools also sit outside this path. A deployed fixture should prove that every approved LLM route reaches duplicate detection before any provider transmission.

Book a demo today.