Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid JSON Schema when using pydantic pattern #8325

Closed
ReinderVosDeWael opened this issue Jan 6, 2025 · 1 comment
Closed

Invalid JSON Schema when using pydantic pattern #8325

ReinderVosDeWael opened this issue Jan 6, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@ReinderVosDeWael
Copy link

What is the issue?

When running ollama chat with structured output and a regex pattern, I get the following error: ollama._types.ResponseError: invalid JSON schema in format. This seems to be exclusive to the pattern argument; removing it resolves the issue.

import pydantic
import ollama

class Test(pydantic.BaseModel):
    text: str = pydantic.Field(..., pattern="[0-9]")

ollama.chat(
    model="llama3.2:1b", 
    format=Test.model_json_schema(), 
    messages=[{"role":"system", "message": "Say 7"}, {"role":"user", "message": "say what"}]
)

OS

macOS

GPU

Other

CPU

Apple

Ollama version

0.5.4

@ReinderVosDeWael ReinderVosDeWael added the bug Something isn't working label Jan 6, 2025
@rick-github
Copy link
Collaborator

--- ./8325.py.orig	2025-01-07 12:58:48.820325234 +1000
+++ ./8325.py	2025-01-07 12:59:18.348706506 +1000
@@ -2,10 +2,10 @@
 import ollama
 
 class Test(pydantic.BaseModel):
-    text: str = pydantic.Field(..., pattern="[0-9]")
+    text: str = pydantic.Field(..., pattern="^[0-9]$")
 
 ollama.chat(
     model="llama3.2:1b", 
     format=Test.model_json_schema(), 
-    messages=[{"role":"system", "message": "Say 7"}, {"role":"user", "message": "say what"}]
+    messages=[{"role":"system", "content": "Say 7"}, {"role":"user", "content": "say what"}]
 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants