Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Googleapis Python genai Interactions Transform

From Leeroopedia
Revision as of 12:49, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Googleapis_Python_genai_Interactions_Transform.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Data_Transformation, SDK_Infrastructure
Last Updated 2026-02-15 14:00 GMT

Overview

Concrete tool for type-based dictionary transformation with field aliasing and format handling for API serialization.

Description

The _transform module provides transform and async_transform functions that convert Python-style typed dictionaries into the JSON structure expected by the API. It handles PropertyInfo annotations for field aliasing, date/base64 formatting, and recursive type traversal.

Usage

Internal infrastructure used by the _interactions request pipeline to serialize typed parameters into API-compatible JSON.

Code Reference

Source Location

Signature

class PropertyInfo:
    alias: str | None
    format: PropertyFormat | None
    format_template: str | None
    discriminator: str | None

def transform(data: _T, expected_type: object) -> _T: ...
def maybe_transform(data: object, expected_type: object) -> Any | None: ...
async def async_transform(data: _T, expected_type: object) -> _T: ...
async def async_maybe_transform(data: object, expected_type: object) -> Any | None: ...

Import

from google.genai._interactions._utils._transform import transform, PropertyInfo

I/O Contract

Inputs

Name Type Required Description
data _T Yes Python dict or typed dict to transform
expected_type type Yes Type annotation defining field mappings

Outputs

Name Type Description
transform returns _T Transformed dict with API-compatible keys and formats

Usage Examples

# Internal usage pattern
from google.genai._interactions._utils._transform import transform

# Transform a TypedDict with field aliases
result = transform(
    {"model_name": "gemini-2.0-flash", "max_tokens": 100},
    ExpectedParamType,  # TypedDict with PropertyInfo annotations
)
# result = {"modelName": "gemini-2.0-flash", "maxTokens": 100}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment