Gemini Function Response IDs Need Exact Call Correlation
Gemini FunctionCall and FunctionResponse each expose an optional id. When a model-issued function call contains an id, the client should return the result with the matching id so parallel and multi-turn tool work stays attached to the correct call. Production systems should preserve optional-field semantics, validate exact matches, and keep local execution authorization separate.

Gemini can return an optional id inside a FunctionCall. The client can then place that identifier in the corresponding FunctionResponse. Google's API contract says the response ID is populated by the client to match the function call ID.
That small field becomes decisive when one model turn proposes several calls. Matching by array position or function name can attach a valid result to the wrong invocation. Exact ID correlation keeps each result tied to the call that requested it.
TL;DR
- Preserve the optional
FunctionCall.idexactly as Gemini returns it. - When that ID is populated, return the corresponding
FunctionResponse.idwith the exact matching value. - Keep absent IDs absent unless the API contract and your client library establish another correlation mechanism. Never invent a Gemini call ID.
- Validate ID, function name, arguments, authorization, local execution, result, and follow-up response as separate evidence.
Google defines both ID fields as optional
The Gemini GenerateContent API reference defines FunctionCall.id as an optional unique identifier of the function call. Its documented behavior says that when the field is populated, the client executes the function call and returns the response with the matching ID.
FunctionResponse.id is also optional. Google describes it as the identifier of the function call that the response is for, populated by the client to match the corresponding function-call ID. The response still has required name and response fields. The ID adds call-level correlation when present.
Optional means a valid payload shape can omit the field. It does not grant permission to synthesize a provider ID and present it as returned evidence. Record presence explicitly, preserve the raw string without case conversion or trimming, and retain the API version and SDK version that parsed it.
An application may still need a local tool execution ID in every case. Generate that value in a separate namespace before running external code. Store it beside the optional Gemini ID so provider correlation and internal execution tracking remain distinguishable.
Exact matching protects parallel calls
The official Gemini function-calling guide says the model can call multiple independent functions in one turn through parallel function calling. Two calls can even target the same function name with different arguments. Function name alone then fails as a unique join field.
Imagine two get_account calls, one for account 104 and another for account 207. A worker pool finishes account 207 first. If the collector attaches results by completion order, the first response slot can receive the second account's data. Exact call ID matching removes that ordering assumption when Gemini populated IDs.
Build a call registry for each model turn. The index should include the conversation or operation boundary plus the raw function-call ID, rather than treating the ID as a universal identifier with undocumented scope. The record should retain candidate index, part index, function name, canonical argument digest, authorization decision, local execution ID, and state.
The AI audit log schema provides the parent identity, route, policy, and attempt fields. The call registry sits below that attempt and creates one immutable child record per proposed invocation.
A match never authorizes execution
A valid ID match proves correlation under the API contract. It says nothing about permission. Before execution, validate the function name against the route allowlist, parse arguments under the declared schema, bind the call to the authenticated user or agent, apply tenant and resource policy, and enforce deadlines and effect limits.
Keep the authorization decision before the execution record. A model can propose delete_record with a perfectly formed ID and arguments. The ID helps identify the proposal.
After execution, validate the result schema and redact fields the model may not receive before constructing FunctionResponse.name, required response, and matching optional id. A failed execution can use an error field inside the required response object, which Google's reference explicitly permits for returning error details to the model.
A per-route AI policy can define allowed function names, argument schemas, data classes, execution budgets, and result filters. The call ID belongs to the evidence for that decision, not to the decision logic itself.
Absent IDs require preserved semantics
When FunctionCall.id is absent, write provider_function_call_id_present: false in the audit. Avoid filling the field with a UUID, array index, function name, or local execution ID. Those values may support local processing, but labeling them as Gemini's ID creates false provenance.
Your client still needs deterministic association inside the turn. Use a separate local call key derived from the operation and observed part location, or use the SDK's documented correlation behavior for that API version, and mark the mechanism as application-generated. If multiple same-name calls without IDs create ambiguity that the implementation cannot resolve safely, hold tool execution and return a controlled error.
When the call ID is present, require an exact response match. Missing, blank, altered, duplicated, or unknown response IDs should stop automatic continuation. Preserve the attempted payload and produce a named finding. A fallback to function name after an ID mismatch defeats the field's purpose.
My opinion is that "best effort" matching has no place in tool execution. A held call is visible and recoverable. A result delivered to the wrong invocation can drive the next model turn with believable, incorrect context.
Multi-turn chains need parent-child evidence
Google's guide describes function calling as a structured exchange among the application, model, and external function. The application sends declarations, Gemini returns a proposed call, the application executes code, and the result goes back for a user-facing response. This can repeat over several turns and can include compositional calling.
Separate records protect each boundary. The initial Gemini response carries responseId, each proposed function call can carry an optional call ID, and every local execution needs a client-controlled ID. The returned function response carries the matching optional call ID before the next Gemini response receives a new response ID.
That chain should be navigable in both directions. An incident responder starting from the final answer must be able to find the tool result, the local execution, the authorization decision, the original function call, and the authenticated HTTP request. Starting from a suspicious tool invocation should lead forward to every model response and application effect that consumed it.
The safe idempotent LLM retries guide matters here because replaying a function response can trigger another model continuation. Keep operation intent, Gemini attempt, tool execution, and downstream effect IDs separate. A retry should reference prior evidence rather than overwrite it.
Response validation needs more than the ID
Before returning a function result to Gemini, compare the response ID with the registered call ID when present. Also compare the function name, operation boundary, candidate and part location, and expected execution state. A matching ID paired with a different name is contradictory evidence and should fail closed.
Validate the required response as a JSON object under the tool's result contract. Google's API allows caller-chosen keys such as output or result, and permits an error key when execution fails. Your route should define the actual shape rather than accepting any object because the transport type is broad.
Protect sensitive tool output before it re-enters the model context. Apply field-level filtering and record a digest of the canonical result, plus a reference to protected raw evidence where retention permits it. The model-facing response and the internal execution result may differ after redaction. Store both digests and the policy version that produced the difference.
The LLM API parameter allowlisting guide covers typed request contracts. Function results need the same discipline on the return path.
Fixtures should force correlation failures
Put a Gemini-compatible stub and controllable tool worker behind the deployed HTTP route. Start with one call containing ID call-a; return a function response with call-a and verify the full chain reaches the continuation request.
Next, emit two parallel calls to the same function with IDs call-a and call-b, then complete them in reverse order. Confirm that arguments and results stay with their original IDs and that completion order changes no association.
Add a missing response ID for a call that supplied one, an unknown ID, a duplicate ID, a case-changed ID, and a correct ID paired with the wrong function name. Every case should stop automatic continuation, retain raw evidence, and emit a stable finding. Then test a call with no ID and verify that the local call key remains clearly marked as application-generated.
Finish with an authorized call followed by a tool timeout and retry. The second local execution needs a separate attempt record. Any external side effect requires its own idempotency protection because matching a Gemini ID alone gives no duplicate-effect guarantee.
DeepInspect
DeepInspect can inspect authenticated user or agent HTTP traffic routed between the application and Gemini. It can require exact function-call and function-response ID matches when IDs are populated, enforce function and argument policy before the request continues, filter tool results returning through the HTTP boundary, and write a per-decision record.
The application owns tool execution, local call IDs, side-effect idempotency, SDK behavior, and any actions taken outside proxied HTTP AI traffic. Direct calls and local worker activity that bypass the proxy remain outside DeepInspect's enforcement.
Book a technical deep dive at deepinspect.ai.
Frequently asked questions
- Are Gemini function-call IDs required?
Google marks
FunctionCall.idas optional. Preserve its absence when the model omits it. Use a separate local execution ID for internal tracking and apply a documented local association rule only when the exchange can be resolved without ambiguity.- What should FunctionResponse.id contain?
When Gemini populated the corresponding function-call ID, set the response ID to that exact value. Google's reference describes the client-populated response field as the identifier used to match the corresponding function call.
- Can function name replace a missing ID?
A name identifies the function type, while multiple calls can use the same name with different arguments. Name-only matching becomes ambiguous in parallel turns. Use a documented local call key and hold execution when safe association is unavailable.
- Does a matching ID authorize the tool call?
Authorization comes from authenticated identity, route policy, allowed function, validated arguments, tenant and resource scope, and effect controls. The ID only correlates the call and response under the API contract.
- How should duplicate function-call IDs be handled?
Preserve both observed calls, emit a duplicate-ID finding within the operation boundary, and stop automatic execution until the ambiguity is resolved. Avoid assigning results by array position or completion order.
- How do retries affect function correlation?
Create a new local execution attempt for each retry and retain the original Gemini call ID as correlation evidence. Protect external effects with a client-controlled idempotency rule. Never overwrite the failed attempt with the retry result.