Gemini tool calling: feedback on unverified task-completion claims

I would like to share a concern from my personal experience using Gemini in tool-enabled workflows: responses that present a task as completed when I cannot verify the intended outcome.

The issue I want to discuss is the gap between a confident completion statement and observable evidence that an action actually succeeded. For a user, this makes it difficult to know whether to trust the result, retry the operation, or investigate a tool or integration failure.

This is qualitative feedback about my own experience, not a benchmark or a claim that all Gemini models or integrations behave this way. I do not have a minimal reproducible example, exact model/version details, or a redacted request/response trace attached to this post, so I cannot isolate the cause to the model rather than the surrounding application or tool integration.

The behavior I would like to see in tool-enabled applications is:

  • Clearly distinguish a proposed action, a tool call that was attempted, a tool-reported success, and a verified final result.
  • Avoid saying a task is complete when the available tool output does not support that conclusion.
  • State when an operation failed, access was unavailable, or the final outcome remains unverified.
  • Where practical, check the resulting state before reporting success.

What is the recommended way to structure Gemini function-calling workflows so that completion claims stay grounded in actual tool results? Are there recommended patterns for reporting partial success and handling missing or ambiguous tool responses?

If a reproducible case is needed, which details would be most useful to include in a follow-up, while keeping credentials and private data out of the report?

Thank you for any guidance.

Hello @Mohamed_Osama,

With custom function calling, the model does not execute functions itself: your application runs the function and sends the result back, and the model writes its final answer from that result, as described in How function calling works. So the most reliable way to keep completion claims grounded is to make every function result explicit:

  • Send back a result for every function call (with the same id as the call), including a clear outcome such as success, failure, or not verified, plus any error message, rather than an empty or ambiguous response. See Send result back to model.
  • Validate function calls before executing them and handle errors in your application, as listed in the function calling best practices.
  • Where it matters, add a function that checks the resulting state, and use the system instruction to tell the model to report success only when a tool result confirms it, and to say clearly when a step failed or could not be verified. The agentic workflows section of the prompt design guide covers recovery, risk assessment, and grounding, and includes a system instruction template you can adapt.

If you have a reproducible case, please share the model ID, your function declarations, the function results you sent back, and the model’s final response, with API keys and personal data removed.

Thank you, Payal, for the clarification and references. I agree that diagnosing this requires separating the function result from the model’s response. I still don’t have a redacted execution trace to share.

I have a follow-up question about a hypothetical case: the application sends an operation that changes state, but the connection drops before the result arrives, or the subsequent state check fails. It is then unclear whether the operation failed or actually completed.

In an application using Gemini function calling, how do you handle this so that the assistant communicates the uncertainty and avoids repeating an operation accidentally? Would it be better to separate the execution function from the verification function, and use an operation ID to help the application determine whether it has already run?

This is a workflow-design question, not the result of an experiment I have tested.

Yes, separating the mutating command from the verification check is the correct pattern (Command-Query Separation). However, to prevent duplicate retries and force Gemini to handle dropped connections safely, you need three core elements:

1. Client-Injected Idempotency Key

Do not let the model generate IDs on retries. Have your client orchestration layer inject a deterministic key into the tool call arguments before sending to your backend:

idempotency_key = hashlib.sha256(f"{session_id}:{turn}:{tool_name}".encode()).hexdigest()[:16]

If the connection dropped after the server processed the write, a subsequent retry with the same key returns the existing record without duplicate execution.

2. Tri-State FunctionResponse on Socket Drops

When a timeout occurs, do not throw an unhandled exception. Return an explicit status payload directly to Gemini:

{
  "operation_id": "tx_948f2b1a",
  "status": "AMBIGUOUS_TIMEOUT",
  "verified": false,
  "instruction": "Connection dropped mid-flight. State unconfirmed. Call check_operation_status(operation_id='tx_948f2b1a'). Do NOT repeat execute."
}

3. Dedicated Verification Tool + Grounding Invariant

Pair your mutating tool with a read-only inspector:

  • execute_order(idempotency_key, ...)
  • check_operation_status(operation_id)

Anchor the model in system_instruction:

“Never claim an operation succeeded unless a tool response returns verified: true. If status is AMBIGUOUS_TIMEOUT, explain the uncertainty to the user, cite the operation ID, and invoke check_operation_status before concluding.”

This architecture gives you end-to-end safety: the backend prevents duplicate execution via the idempotency key, while the model is constrained by structured status flags rather than guessing after network drops.

Thank you, this makes the idea clearer to me, especially that preventing duplicates needs to be the responsibility of the application and backend, rather than just an instruction to the model.

There is one point I would like to clarify: if the same operation is retried in a later message, should we keep its original ID instead of generating a new one based on the turn number? And if the connection drops before the backend returns an operation ID, should we use the client-generated key to look up its status?

I have not tested this design yet, but clarifying those two points would help me understand how to handle a dropped connection without duplicating the operation.