Skip to content

fix(py/plugins/ollama): preserve tool argument enum choices - #190

Merged
huangjeff5 merged 2 commits into
genkit-ai:mainfrom
FOWEPJF255:fix/ollama-tool-property-enums
Nov 30, 2026
Merged

huangjeff5 merged 2 commits into
genkit-ai:mainfrom
FOWEPJF255:fix/ollama-tool-property-enums

Conversation

@FOWEPJF255

Copy link
Copy Markdown
Contributor

A Genkit Python tool declared with Literal['north', 'south'] now sends those choices to Ollama in its tool schema. Previously the model only saw a string property and could choose a value that the tool would reject.

class InventoryQuery(BaseModel):
    warehouse: Literal['north', 'south']

@ai.tool()
async def check_inventory(query: InventoryQuery) -> str:
    """Look up inventory in a warehouse."""
    return query.warehouse

await ai.generate(model='ollama/llama3.2', prompt='Check inventory.', tools=[check_inventory])
# Ollama receives warehouse.enum = ['north', 'south'].

Fixes #189.

Changes

  • Keep each tool property's enum values in the Ollama chat request. Ordinary properties still have no enum.

Breaking changes

None.

Validation

  • Reproduced on main with the real Ollama Python client's HTTP request captured by httpx.MockTransport. The regression failed before the fix and checks string and integer enum values as well as an unrestricted string.
  • Ollama plugin suite without live server tests: 252 passed and 5 subtests passed on Python 3.12.10. Set NO_PROXY=* so local HTTP fixture transports handle the test requests.
  • Ruff lint, Ruff format check, and git diff --check passed.

OpenAI Codex assisted with reproduction, implementation, testing, and drafting this pull request.

@huangjeff5 huangjeff5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean fix. Left one non-blocking note on optional literals.

@huangjeff5
huangjeff5 enabled auto-merge (squash) November 30, 2026 19:51
@huangjeff5
huangjeff5 disabled auto-merge November 30, 2026 20:01
@huangjeff5
huangjeff5 enabled auto-merge (squash) November 30, 2026 20:05
@huangjeff5
huangjeff5 merged commit db9cc6c into genkit-ai:main Nov 30, 2026
20 checks passed
@huangjeff5 huangjeff5 mentioned this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ollama drops enum choices from tool input schemas

2 participants