[GH-ISSUE #8562] None value being returned from with_structured_output request #5528

Closed
opened 2026-04-12 16:46:40 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @jonmach on GitHub (Jan 24, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/8562

What is the issue?

Python versions are:

langchain 0.3.15
langchain-community 0.3.15
langchain-core 0.3.31
langchain-ollama 0.2.2
ollama 0.4.7

Running ollama 0.5.7 (pip install -U ollama did not increase the version beyond 0.4.7)


Using with_structured_output() seems to work for a very simple example such as the following:

from langchain_ollama import ChatOllama
from typing import Optional
from pydantic import BaseModel, Field

class Person(BaseModel):
    name: str
    age: int

llm = ChatOllama(
    model="qwen2.5:1.5b",
    temperature=0,
).with_structured_output(Person)
llm.invoke("Erick 27")

However, for a more complex requirement, it fails with Ollama returning a value of None.

from pydantic import BaseModel, Field
from typing import Optional
from openai import OpenAI
from langchain_ollama import ChatOllama

# Define the output model
class Experience(BaseModel):
    company: str = Field(..., description="The name of the company.")
    position: str = Field(..., description="The job title held at the company.")
    start_date: str = Field(..., description="The date when you started working at the company.")
    end_date: str = Field(..., description="The date when you left the company. If still employed, use 'Present'.")

class Education(BaseModel):
    institution_name: str = Field(..., description="The name of the educational institution.")
    degree: str = Field(..., description="The degree obtained from the institution.")
    start_date: str = Field(..., description="The date when you started attending school at the institution.")
    end_date: str = Field(..., description="The date when you graduated. If still enrolled, use 'Present'.")

class Resume(BaseModel):
    full_name: str = Field(..., description="The full name of the person on the resume.")
    contact_email: str = Field(..., description="The email address for contacting the person.")
    phone_number: str = Field(..., description="The phone number for contacting the person.")
    summary: str = Field(..., description="A brief summary of the person's career highlights.")
    experience: Optional[list[Experience]] = Field([], description="List of experiences held by the person.")
    education: Optional[list[Education]] = Field([], description="List of educational institutions attended by the person.")

with open('CVs/resume.md', 'r') as file:
    resume_data = file.read()

verbose=True
model = "qwen2.5:14b"

prompt = f""" 
Analyse the following resume from the content between the triple backticks below:  For the resume below, identify the following information:
    1) Their personal details, including name, email, phone number and anything else they provide.
    2) An overall summary of their experience to provide a general background.
    3) A list of the companies they have worked for. This should include the company name, the dates they started and and ended working for the company, and the tasks and activities they carried out.
    4) A list of universities or colleges that the person went to. This should include the name of the college the title of the qualification, and the dates they started and ended.

    The raw data is here: 
    
       ```{resume_data}```
"""

# print(prompt)

llm = ChatOllama( model=model,
                    num_ctx = 32000,
                    timeout = 600,
                    temperature=0.0,
                    verboseness = verbose,
                    response = "json")

structured_llm = llm.with_structured_output(Resume)
print("Calling LLM")
response = structured_llm.invoke(prompt)
print(response)

It also fails without the 'response = "json" included.

I just get a None response.

Oddly, this is not consistent. Sometimes, I get back a response, but it fails satisfying the Resume type. because it won't find education items. Even though Education is an optional type in the Resume class.

For some reason, I cannot upload the small resume file, so here it is in cleartext:


## **Professional Experience**

### **Senior Software Engineer**

**Tech Innovators Inc.**  
_June 2015 – Present_

- Designed and implemented scalable microservices architecture for a SaaS platform, improving performance by 30%.
- Led a team of 12 engineers, mentoring junior developers and conducting regular code reviews.
- Integrated AI/ML capabilities into legacy systems, increasing operational efficiency by 20%.
- Championed DevOps practices, reducing deployment times from days to hours.

### **Software Architect**

**NextGen Solutions**  
_March 2010 – May 2015_

- Architected and delivered a real-time analytics platform for financial services, handling millions of transactions daily.
- Migrated a monolithic system to a distributed microservices-based architecture, enabling faster feature delivery.
- Partnered with product managers to define technical requirements and roadmap, aligning business goals with engineering efforts.

### **Lead Developer**

**Alpha Development Corp.**  
_January 2005 – February 2010_

- Built a high-availability e-commerce platform that handled over 500,000 daily users.
- Created APIs to integrate third-party payment gateways, enhancing user experience and reducing downtime.
- Conducted performance optimizations that improved application speed by 40%.

### **Software Engineer**

**CodeSphere LLC**  
_June 2000 – December 2004_

- Developed enterprise-grade web applications using Java and C++.
- Automated internal processes, saving the company 15% in operational costs annually.
- Collaborated with cross-functional teams to deliver projects on time and within budget.

---

## **Education**

### **Master of Science in Computer Science**

**Massachusetts Institute of Technology**  
_August 1998 – May 2000_

### **Bachelor of Science in Computer Science**

**University of California, Berkeley**  
_August 1994 – May 1998_

---

## **Skills**

- Programming Languages: Python, Java, C++, JavaScript
- Cloud Platforms: AWS, Azure, Google Cloud
- Architecture: Microservices, Distributed Systems, RESTful APIs
- Tools: Docker, Kubernetes, Terraform
- Agile Development, DevOps, AI/ML Integration

---

## **Certifications**

- AWS Certified Solutions Architect – Professional
- Certified Kubernetes Administrator (CKA)
- Certified ScrumMaster (CSM)

---

## **Contact**

Feel free to reach out via email or phone for opportunities or collaboration.

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.5.7

Originally created by @jonmach on GitHub (Jan 24, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/8562 ### What is the issue? Python versions are: langchain 0.3.15 langchain-community 0.3.15 langchain-core 0.3.31 langchain-ollama 0.2.2 ollama 0.4.7 Running ollama 0.5.7 (pip install -U ollama did not increase the version beyond 0.4.7) --- Using **with_structured_output()** seems to work for a very simple example such as the following: ``` from langchain_ollama import ChatOllama from typing import Optional from pydantic import BaseModel, Field class Person(BaseModel): name: str age: int llm = ChatOllama( model="qwen2.5:1.5b", temperature=0, ).with_structured_output(Person) llm.invoke("Erick 27") ``` However, for a more complex requirement, it fails with Ollama returning a value of None. ``` from pydantic import BaseModel, Field from typing import Optional from openai import OpenAI from langchain_ollama import ChatOllama # Define the output model class Experience(BaseModel): company: str = Field(..., description="The name of the company.") position: str = Field(..., description="The job title held at the company.") start_date: str = Field(..., description="The date when you started working at the company.") end_date: str = Field(..., description="The date when you left the company. If still employed, use 'Present'.") class Education(BaseModel): institution_name: str = Field(..., description="The name of the educational institution.") degree: str = Field(..., description="The degree obtained from the institution.") start_date: str = Field(..., description="The date when you started attending school at the institution.") end_date: str = Field(..., description="The date when you graduated. If still enrolled, use 'Present'.") class Resume(BaseModel): full_name: str = Field(..., description="The full name of the person on the resume.") contact_email: str = Field(..., description="The email address for contacting the person.") phone_number: str = Field(..., description="The phone number for contacting the person.") summary: str = Field(..., description="A brief summary of the person's career highlights.") experience: Optional[list[Experience]] = Field([], description="List of experiences held by the person.") education: Optional[list[Education]] = Field([], description="List of educational institutions attended by the person.") with open('CVs/resume.md', 'r') as file: resume_data = file.read() verbose=True model = "qwen2.5:14b" prompt = f""" Analyse the following resume from the content between the triple backticks below: For the resume below, identify the following information: 1) Their personal details, including name, email, phone number and anything else they provide. 2) An overall summary of their experience to provide a general background. 3) A list of the companies they have worked for. This should include the company name, the dates they started and and ended working for the company, and the tasks and activities they carried out. 4) A list of universities or colleges that the person went to. This should include the name of the college the title of the qualification, and the dates they started and ended. The raw data is here: ```{resume_data}``` """ # print(prompt) llm = ChatOllama( model=model, num_ctx = 32000, timeout = 600, temperature=0.0, verboseness = verbose, response = "json") structured_llm = llm.with_structured_output(Resume) print("Calling LLM") response = structured_llm.invoke(prompt) print(response) ``` It also fails without the 'response = "json" included. I just get a None response. Oddly, this is not consistent. Sometimes, I get back a response, but it fails satisfying the Resume type. because it won't find education items. Even though Education is an optional type in the Resume class. For some reason, I cannot upload the small resume file, so here it is in cleartext: --- ``` ## **Professional Experience** ### **Senior Software Engineer** **Tech Innovators Inc.** _June 2015 – Present_ - Designed and implemented scalable microservices architecture for a SaaS platform, improving performance by 30%. - Led a team of 12 engineers, mentoring junior developers and conducting regular code reviews. - Integrated AI/ML capabilities into legacy systems, increasing operational efficiency by 20%. - Championed DevOps practices, reducing deployment times from days to hours. ### **Software Architect** **NextGen Solutions** _March 2010 – May 2015_ - Architected and delivered a real-time analytics platform for financial services, handling millions of transactions daily. - Migrated a monolithic system to a distributed microservices-based architecture, enabling faster feature delivery. - Partnered with product managers to define technical requirements and roadmap, aligning business goals with engineering efforts. ### **Lead Developer** **Alpha Development Corp.** _January 2005 – February 2010_ - Built a high-availability e-commerce platform that handled over 500,000 daily users. - Created APIs to integrate third-party payment gateways, enhancing user experience and reducing downtime. - Conducted performance optimizations that improved application speed by 40%. ### **Software Engineer** **CodeSphere LLC** _June 2000 – December 2004_ - Developed enterprise-grade web applications using Java and C++. - Automated internal processes, saving the company 15% in operational costs annually. - Collaborated with cross-functional teams to deliver projects on time and within budget. --- ## **Education** ### **Master of Science in Computer Science** **Massachusetts Institute of Technology** _August 1998 – May 2000_ ### **Bachelor of Science in Computer Science** **University of California, Berkeley** _August 1994 – May 1998_ --- ## **Skills** - Programming Languages: Python, Java, C++, JavaScript - Cloud Platforms: AWS, Azure, Google Cloud - Architecture: Microservices, Distributed Systems, RESTful APIs - Tools: Docker, Kubernetes, Terraform - Agile Development, DevOps, AI/ML Integration --- ## **Certifications** - AWS Certified Solutions Architect – Professional - Certified Kubernetes Administrator (CKA) - Certified ScrumMaster (CSM) --- ## **Contact** Feel free to reach out via email or phone for opportunities or collaboration. ``` ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.5.7
GiteaMirror added the bug label 2026-04-12 16:46:40 -05:00
Author
Owner

@rick-github commented on GitHub (Jan 24, 2025):

The issues seems to be with langchain or one of the dependent libraries. This is the request sent to ollama:

{
  "model": "qwen2.5:14b",
  "stream": true,
  "options": {
    "num_ctx": 32000,
    "temperature": 0.0
  },
  "messages": [
    {
      "role": "user",
      "content": " \nAnalyse the following ... or collaboration.\n```\n"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "Resume",
        "description": "",
        "parameters": {
          "type": "object",
          "required": [
            "full_name",
            "contact_email",
            "phone_number",
            "summary"
          ],
          "properties": {
            "full_name": {
              "type": "string",
              "description": "The full name of the person on the resume."
            },
            "contact_email": {
              "type": "string",
              "description": "The email address for contacting the person."
            },
            "phone_number": {
              "type": "string",
              "description": "The phone number for contacting the person."
            },
            "summary": {
              "type": "string",
              "description": "A brief summary of the person's career highlights."
            },
            "experience": {
              "description": "List of experiences held by the person."
            },
            "education": {
              "description": "List of educational institutions attended by the person."
            }
          }
        }
      }
    }
  ]
}

The schema hasn't been recursed and is passed as a tool definition, so the model doesn't know what data is needed. It does its best and fills in a bunch of details, but the returned data fails validation checks.

If the request is sent directly to ollama, the results are better.

--- 8562.py.orig	2025-01-24 12:56:08.877308140 +0100
+++ 8562.py	2025-01-24 12:58:33.963872768 +0100
@@ -44,6 +44,16 @@
 
 # print(prompt)
 
+if True:
+  import ollama, json, sys
+  response = ollama.chat(model=model,
+                      messages=[{"role":"user","content":prompt}],
+                      options={"num_ctx":32000, "temperature":0.0},
+                      format=Resume.model_json_schema(),
+      )
+  print(json.dumps(json.loads(response.message.content), indent=4))
+  sys.exit(0)
+
 llm = ChatOllama( model=model,
                     num_ctx = 32000,
                     timeout = 600,

The prompt sent to ollama has the full schema in the format field:

{
  "model": "qwen2.5:14b",
  "stream": false,
  "options": {
    "num_ctx": 32000,
    "temperature": 0.0
  },
  "format": {
    "$defs": {
      "Education": {
        "properties": {
          "institution_name": {
            "description": "The name of the educational institution.",
            "title": "Institution Name",
            "type": "string"
          },
          "degree": {
            "description": "The degree obtained from the institution.",
            "title": "Degree",
            "type": "string"
          },
          "start_date": {
            "description": "The date when you started attending school at the institution.",
            "title": "Start Date",
            "type": "string"
          },
          "end_date": {
            "description": "The date when you graduated. If still enrolled, use 'Present'.",
            "title": "End Date",
            "type": "string"
          }
        },
        "required": [
          "institution_name",
          "degree",
          "start_date",
          "end_date"
        ],
        "title": "Education",
        "type": "object"
      },
      "Experience": {
        "properties": {
          "company": {
            "description": "The name of the company.",
            "title": "Company",
            "type": "string"
          },
          "position": {
            "description": "The job title held at the company.",
            "title": "Position",
            "type": "string"
          },
          "start_date": {
            "description": "The date when you started working at the company.",
            "title": "Start Date",
            "type": "string"
          },
          "end_date": {
            "description": "The date when you left the company. If still employed, use 'Present'.",
            "title": "End Date",
            "type": "string"
          }
        },
        "required": [
          "company",
          "position",
          "start_date",
          "end_date"
        ],
        "title": "Experience",
        "type": "object"
      }
    },
    "properties": {
      "full_name": {
        "description": "The full name of the person on the resume.",
        "title": "Full Name",
        "type": "string"
      },
      "contact_email": {
        "description": "The email address for contacting the person.",
        "title": "Contact Email",
        "type": "string"
      },
      "phone_number": {
        "description": "The phone number for contacting the person.",
        "title": "Phone Number",
        "type": "string"
      },
      "summary": {
        "description": "A brief summary of the person's career highlights.",
        "title": "Summary",
        "type": "string"
      },
      "experience": {
        "anyOf": [
          {
            "items": {
              "$ref": "#/$defs/Experience"
            },
            "type": "array"
          },
          {
            "type": "null"
          }
        ],
        "default": [],
        "description": "List of experiences held by the person.",
        "title": "Experience"
      },
      "education": {
        "anyOf": [
          {
            "items": {
              "$ref": "#/$defs/Education"
            },
            "type": "array"
          },
          {
            "type": "null"
          }
        ],
        "default": [],
        "description": "List of educational institutions attended by the person.",
        "title": "Education"
      }
    },
    "required": [
      "full_name",
      "contact_email",
      "phone_number",
      "summary"
    ],
    "title": "Resume",
    "type": "object"
  },
  "messages": [
    {
      "role": "user",
      "content": " \nAnalyse the following ... or collaboration.\n```\n"
    }
  ],
  "tools": []
}

The returned data looks complete:

{
    "full_name": "Not provided in the resume",
    "contact_email": "Not explicitly provided, but a placeholder is given: Feel free to reach out via email",
    "phone_number": "Not provided in the resume",
    "summary": "The individual has over two decades of experience in software engineering and architecture roles. They have worked at several companies including Tech Innovators Inc., NextGen Solutions, Alpha Development Corp., and CodeSphere LLC. Their career highlights include designing scalable microservices architectures, leading development teams, integrating AI/ML capabilities into legacy systems, and automating internal processes to reduce operational costs.",
    "experience": [
        {
            "company": "Tech Innovators Inc.",
            "position": "Senior Software Engineer",
            "start_date": "June 2015",
            "end_date": "Present"
        },
        {
            "company": "NextGen Solutions",
            "position": "Software Architect",
            "start_date": "March 2010",
            "end_date": "May 2015"
        },
        {
            "company": "Alpha Development Corp.",
            "position": "Lead Developer",
            "start_date": "January 2005",
            "end_date": "February 2010"
        },
        {
            "company": "CodeSphere LLC",
            "position": "Software Engineer",
            "start_date": "June 2000",
            "end_date": "December 2004"
        }
    ],
    "education": [
        {
            "institution_name": "Massachusetts Institute of Technology",
            "degree": "Master of Science in Computer Science",
            "start_date": "August 1998",
            "end_date": "May 2000"
        },
        {
            "institution_name": "University of California, Berkeley",
            "degree": "Bachelor of Science in Computer Science",
            "start_date": "August 1994",
            "end_date": "May 1998"
        }
    ]
}

I ran the modified script about 20 times and got the same output.

You mention occasionally getting a response. All my runs using ChatOllama failed with validation errors, so it seems there's a difference in our environments that may result in your code actually sending a valid format field. Unfortunately I don't know enough about langchain to dig any further.

<!-- gh-comment-id:2612400640 --> @rick-github commented on GitHub (Jan 24, 2025): The issues seems to be with langchain or one of the dependent libraries. This is the request sent to ollama: ```json { "model": "qwen2.5:14b", "stream": true, "options": { "num_ctx": 32000, "temperature": 0.0 }, "messages": [ { "role": "user", "content": " \nAnalyse the following ... or collaboration.\n```\n" } ], "tools": [ { "type": "function", "function": { "name": "Resume", "description": "", "parameters": { "type": "object", "required": [ "full_name", "contact_email", "phone_number", "summary" ], "properties": { "full_name": { "type": "string", "description": "The full name of the person on the resume." }, "contact_email": { "type": "string", "description": "The email address for contacting the person." }, "phone_number": { "type": "string", "description": "The phone number for contacting the person." }, "summary": { "type": "string", "description": "A brief summary of the person's career highlights." }, "experience": { "description": "List of experiences held by the person." }, "education": { "description": "List of educational institutions attended by the person." } } } } } ] } ``` The schema hasn't been recursed and is passed as a `tool` definition, so the model doesn't know what data is needed. It does its best and fills in a bunch of details, but the returned data fails validation checks. If the request is sent directly to ollama, the results are better. ```diff --- 8562.py.orig 2025-01-24 12:56:08.877308140 +0100 +++ 8562.py 2025-01-24 12:58:33.963872768 +0100 @@ -44,6 +44,16 @@ # print(prompt) +if True: + import ollama, json, sys + response = ollama.chat(model=model, + messages=[{"role":"user","content":prompt}], + options={"num_ctx":32000, "temperature":0.0}, + format=Resume.model_json_schema(), + ) + print(json.dumps(json.loads(response.message.content), indent=4)) + sys.exit(0) + llm = ChatOllama( model=model, num_ctx = 32000, timeout = 600, ``` The prompt sent to ollama has the full schema in the `format` field: ```json { "model": "qwen2.5:14b", "stream": false, "options": { "num_ctx": 32000, "temperature": 0.0 }, "format": { "$defs": { "Education": { "properties": { "institution_name": { "description": "The name of the educational institution.", "title": "Institution Name", "type": "string" }, "degree": { "description": "The degree obtained from the institution.", "title": "Degree", "type": "string" }, "start_date": { "description": "The date when you started attending school at the institution.", "title": "Start Date", "type": "string" }, "end_date": { "description": "The date when you graduated. If still enrolled, use 'Present'.", "title": "End Date", "type": "string" } }, "required": [ "institution_name", "degree", "start_date", "end_date" ], "title": "Education", "type": "object" }, "Experience": { "properties": { "company": { "description": "The name of the company.", "title": "Company", "type": "string" }, "position": { "description": "The job title held at the company.", "title": "Position", "type": "string" }, "start_date": { "description": "The date when you started working at the company.", "title": "Start Date", "type": "string" }, "end_date": { "description": "The date when you left the company. If still employed, use 'Present'.", "title": "End Date", "type": "string" } }, "required": [ "company", "position", "start_date", "end_date" ], "title": "Experience", "type": "object" } }, "properties": { "full_name": { "description": "The full name of the person on the resume.", "title": "Full Name", "type": "string" }, "contact_email": { "description": "The email address for contacting the person.", "title": "Contact Email", "type": "string" }, "phone_number": { "description": "The phone number for contacting the person.", "title": "Phone Number", "type": "string" }, "summary": { "description": "A brief summary of the person's career highlights.", "title": "Summary", "type": "string" }, "experience": { "anyOf": [ { "items": { "$ref": "#/$defs/Experience" }, "type": "array" }, { "type": "null" } ], "default": [], "description": "List of experiences held by the person.", "title": "Experience" }, "education": { "anyOf": [ { "items": { "$ref": "#/$defs/Education" }, "type": "array" }, { "type": "null" } ], "default": [], "description": "List of educational institutions attended by the person.", "title": "Education" } }, "required": [ "full_name", "contact_email", "phone_number", "summary" ], "title": "Resume", "type": "object" }, "messages": [ { "role": "user", "content": " \nAnalyse the following ... or collaboration.\n```\n" } ], "tools": [] } ``` The returned data looks complete: ```json { "full_name": "Not provided in the resume", "contact_email": "Not explicitly provided, but a placeholder is given: Feel free to reach out via email", "phone_number": "Not provided in the resume", "summary": "The individual has over two decades of experience in software engineering and architecture roles. They have worked at several companies including Tech Innovators Inc., NextGen Solutions, Alpha Development Corp., and CodeSphere LLC. Their career highlights include designing scalable microservices architectures, leading development teams, integrating AI/ML capabilities into legacy systems, and automating internal processes to reduce operational costs.", "experience": [ { "company": "Tech Innovators Inc.", "position": "Senior Software Engineer", "start_date": "June 2015", "end_date": "Present" }, { "company": "NextGen Solutions", "position": "Software Architect", "start_date": "March 2010", "end_date": "May 2015" }, { "company": "Alpha Development Corp.", "position": "Lead Developer", "start_date": "January 2005", "end_date": "February 2010" }, { "company": "CodeSphere LLC", "position": "Software Engineer", "start_date": "June 2000", "end_date": "December 2004" } ], "education": [ { "institution_name": "Massachusetts Institute of Technology", "degree": "Master of Science in Computer Science", "start_date": "August 1998", "end_date": "May 2000" }, { "institution_name": "University of California, Berkeley", "degree": "Bachelor of Science in Computer Science", "start_date": "August 1994", "end_date": "May 1998" } ] } ``` I ran the modified script about 20 times and got the same output. You mention occasionally getting a response. All my runs using `ChatOllama` failed with validation errors, so it seems there's a difference in our environments that may result in your code actually sending a valid `format` field. Unfortunately I don't know enough about langchain to dig any further.
Author
Owner

@jonmach commented on GitHub (Jan 24, 2025):

Thanks for your comprehensive dig into this. How did you get a trace of what Ollama was doing, other than starting everything in DEBUG mode?

I'll dig further, and see how I can do this directly through the Ollama chat() function.

<!-- gh-comment-id:2612432914 --> @jonmach commented on GitHub (Jan 24, 2025): Thanks for your comprehensive dig into this. How did you get a trace of what Ollama was doing, other than starting everything in DEBUG mode? I'll dig further, and see how I can do this directly through the Ollama chat() function.
Author
Owner

@rick-github commented on GitHub (Jan 24, 2025):

I used strace to monitor the wire traffic. ktrace is apparently the MacOS equivalent since SIP broke dtruss. tcpflow or tcpdump would also work on Linux, I'm guessing something similar is available for MacOS.

<!-- gh-comment-id:2612453124 --> @rick-github commented on GitHub (Jan 24, 2025): I used [`strace`](https://man7.org/linux/man-pages/man1/strace.1.html) to monitor the wire traffic. `ktrace` is apparently the MacOS equivalent since SIP broke `dtruss`. `tcpflow` or `tcpdump` would also work on Linux, I'm guessing something similar is available for MacOS.
Author
Owner

@jonmach commented on GitHub (Jan 24, 2025):

Thank you - Works perfectly, even on much larger content and with more complex class definition.

I'll open a bug with langchain.

<!-- gh-comment-id:2612530109 --> @jonmach commented on GitHub (Jan 24, 2025): Thank you - Works perfectly, even on much larger content and with more complex class definition. I'll open a bug with langchain.
Author
Owner

@t0d4 commented on GitHub (Jan 27, 2025):

Hi, I've also been troubled by this for several days, but after inspecting the docs I found that this was as designed.

https://python.langchain.com/api_reference/ollama/chat_models/langchain_ollama.chat_models.ChatOllama.html#langchain_ollama.chat_models.ChatOllama.with_structured_output

Read about the method argument (whose default value is "function_calling") of the with_structured_output(). I solved the issue by specifying method=json_schema, though I wish this were the default.

<!-- gh-comment-id:2615118324 --> @t0d4 commented on GitHub (Jan 27, 2025): Hi, I've also been troubled by this for several days, but after inspecting the docs I found that this was as designed. https://python.langchain.com/api_reference/ollama/chat_models/langchain_ollama.chat_models.ChatOllama.html#langchain_ollama.chat_models.ChatOllama.with_structured_output Read about the `method` argument (whose default value is "function_calling") of the `with_structured_output()`. I solved the issue by specifying `method=json_schema`, though I wish this were the default.
Author
Owner

@jonmach commented on GitHub (Jan 27, 2025):

Thanks @t0d4 - Also works perfectly when using this. I'll also go update the langchain issue that I raised.

<!-- gh-comment-id:2615341754 --> @jonmach commented on GitHub (Jan 27, 2025): Thanks @t0d4 - Also works perfectly when using this. I'll also go update the langchain issue that I raised.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#5528