Skip to content

Add AI schema models for structured output and response validation - #4289

Merged
vabene1111 merged 2 commits into
TandoorRecipes:developfrom
arsaboo:ollama
Sep 7, 2026
Merged

vabene1111 merged 2 commits into
TandoorRecipes:developfrom
arsaboo:ollama

Conversation

@arsaboo

@arsaboo arsaboo commented Dec 6, 2025

Copy link
Copy Markdown
Contributor

Introduce Pydantic models for structured output schemas related to recipes and nutrition information.

Implement validation functions to ensure responses from the AI conform to these schemas, enhancing response integrity and usability. Update response formats in API requests to utilize the new schemas.

Fixes #4246

@CLAassistant

CLAassistant commented Dec 6, 2025 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@arsaboo

arsaboo commented Dec 6, 2025

Copy link
Copy Markdown
Contributor Author

@vabene1111 would love for you to test this approach out. I think recipes will be more reliable with such structured outputs in the long run.

@vabene1111

Copy link
Copy Markdown
Collaborator

interesting approach, looks good on first glance. Currently not much time but will take a look

@CNCmarlin

Copy link
Copy Markdown

I'm curious how many people use the ai import feature? I'm trying to use local AI for my mother import of all her paper Recepies, but do to the limited amount of schema I have access to I cannot tune the output. This sounds like a promising route to fix these issues surrounding the ai import.

I wish I could support you with coding, but cannot code. I love this project and hope to see this implemented in the future, or something like this. Thanks

PS I was able to get image working but had to add a model file/ prompt using ollama to get the AI to satisfy the strict structure expected by the parser, works most of the time, but could be better. Have not been able to get PDFs to work, but saw another open ticket stating what I believe to be the issue. It seems the endpoint hard coded only accept images and not PDFs (a litellm issue) if I remember I can find it and post the link here.

@vabene1111
vabene1111 merged commit 2264dce into TandoorRecipes:develop Sep 7, 2026
@github-project-automation github-project-automation Bot moved this to Done in Tandoor 2 Sep 7, 2026
@vabene1111

Copy link
Copy Markdown
Collaborator

had to revert this. Did not work right away so I had to fix the import as Recipe was referencing the django ORM model and not your custom schema.

After that this was still not working (tested with gemini-flash-latest). Reverting to the old system worked without problems.

Feel free to try again but please make sure to test with the most common models (gemini/gpt).

\recipes\cookbook\views\api.py", line 2849, in post
    data_json = json.loads(response_text)
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\json\decoder.py", line 338, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\json\decoder.py", line 356, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

vabene1111 added a commit that referenced this pull request Sep 7, 2026
This reverts commit 2264dce, reversing
changes made to 6451ebe.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

AI import with Ollama does not work (json.decoder.JSONDecodeError)

4 participants