agentleFS
salmandevsalmandev/everything-gemini/skills/gemini-function-calling/SKILL.md

gemini-function-calling

Skill2 starsChanged 28 days agoApache-2.0View on GitHub

Designs, validates, and tests production Gemini function calling schemas, structured outputs with Pydantic/JSON Schema, parallel tool dispatch, and error recovery loops.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When an application requires guaranteed JSON outputs matching a domain model, configure response_mime_type="application/json" and supply a …

    line 42
  2. Distinctive:

    When a tool execution fails (e.g., database timeout or syntax error):

    line 71

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Gemini Function Calling & Structured Outputs

Overview

Gemini models support native, high-precision function calling and constrained JSON output schemas. This skill outlines best practices for defining deterministic tool declarations, handling parallel tool invocations, enforcing response schemas, and recovering gracefully from tool execution exceptions.

Core Capabilities

1. Function Declarations (Tools)

Define tools with clear semantics, parameter types, descriptions, and required constraints:

from google.genai import types

def get_db_schema_declaration() -> types.FunctionDeclaration:
    return types.FunctionDeclaration(
        name="query_database",
        description="Executes a read-only SQL query against the application replica.",
        parameters=types.Schema(
            type=types.Type.OBJECT,
            properties={
                "query": types.Schema(
                    type=types.Type.STRING,
                    description="The SQL query to execute. Must be a SELECT statement."
                ),
                "limit": types.Schema(
                    type=types.Type.INTEGER,
                    description="Maximum number of rows to return (default: 50, max: 200)."
                )
            },
            required=["query"]
        )
    )

2. Structured JSON Outputs (response_schema)

When an application requires guaranteed JSON outputs matching a domain model, configure response_mime_type="application/json" and supply a response_schema (or Pydantic class):

from pydantic import BaseModel, Field

class CodeAnalysisReport(BaseModel):
    summary: str = Field(description="High-level architecture assessment")
    vulnerabilities: list[str] = Field(description="List of identified security vulnerabilities")
    risk_score: int = Field(description="Risk rating from 1 (lowest) to 10 (critical)", ge=1, le=10)

config = types.GenerateContentConfig(
    response_mime_type="application/json",
    response_schema=CodeAnalysisReport,
    temperature=0.1
)

3. Parallel & Multi-Turn Function Calling

  • Parallel Dispatch: Gemini can return multiple function calls in a single response turn. Process independent read operations concurrently using asyncio.gather or Promise.all.
  • Function Response Envelope: Return the results of each tool back to the model with matching tool names and execution status:
tool_response_part = types.Part.from_function_response(
    name="query_database",
    response={"status": "success", "rows": rows, "count": len(rows)}
)

4. Error Recovery & Defensive Handling

When a tool execution fails (e.g., database timeout or syntax error):

  1. Never suppress the error silently: Feed the error back to Gemini in the function response envelope.
  2. Include Contextual Remediation: Inform the model why the call failed so it can self-correct in the next turn:
error_part = types.Part.from_function_response(
    name="query_database",
    response={
        "status": "error",
        "error_code": "SYNTAX_ERROR",
        "message": "Column 'user_id' does not exist in table 'accounts'. Available columns: [id, account_number, balance]."
    }
)

Verification Checklist

  • Tool parameters have unambiguous description fields
  • required fields explicitly defined
  • Read-only vs destructive operations strictly separated
  • Tool execution errors safely fed back to model for autonomous self-correction

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.