Please Implement Structured Outputs for openai models!

The idea is:

The idea is to implement https://platform.openai.com/docs/guides/structured-outputs so that it can be used in AI nodes when using openai models. This is the ONLY really reliable way to get 100% valid json responses.

My use case:

When using models like gpt-40-mini at least 1 out of hundred requests with a json output is invalid and you either have to use an autofix output formater which costs extra tokens and is very slow, or do some kind of ugly error handling. None of this would be necessary if you just implement the Structured Output standard. I’ve been using it in python for months now and never ever had a wonk output in millions of requests.

I think it would be beneficial to add this because:

It would really be a big step for n8n in providing a platform for enterprise grade AI solutions.

Any resources to support this?

Are you willing to work on this?

Sure but you won’t need me it is super easy to implement

No this is a feature request for n8n. Meaning I would love it if the n8n team integrates this in their platform :slight_smile:

With GPT assistants, there is an option for JSON or JSON schema for output type. This allows you to force the model to output a pure JSON, validated on their side. This can be used with an API call to accomplish what you want.

Good idea, but using an api call directly I can also just specify the json output format in the body and achieve the same thing. I have been using this method when I only needed one isolated llm call.
My request would be to implement it in the AI nodes so that it can be used much more easily and also for things like agents, which would be very hard to do with pure api calls in n8n.

4 Likes

Can you share an example of how to do this in n8n? Thanks!

Sure here is a workflow that uses this method in the http request node:

3 Likes

a must have! long prompts give inconsistent results in output and cannot be parsed :frowning:

just found this! https://www.npmjs.com/package/n8n-nodes-openai-structured-outputs

Great tip with the n8n-nodes-openai-structured-outputs thingy

however - this modul calls the completions api, i would really like to use the new responses api

Is it already planned to extend the existing openai integrations to work with structured output? Should probably not be a big change, right?

Actually, this module internally uses the native openai structured output api. It has worked for me perfectly. It solves all the problem!! :white_check_mark:

Agreed that n8n-nodes-openai-structured-outputs solves most of the problems.

However, as i mentioned in my previous response, it calls the completions api and i would like to use the responses api. (The used api is also documented here: GitHub - crucerlabs/n8n-nodes-openai-structured-outputs: Extract structured JSON from unstructured text by leveraging OpenAI’s Structured Outputs feature with a JSON Schema.)

This by itself is not really an issue, just a nice to have. The nodes provided by n8n itself at least for me are to be preferred for the following reasons:

  • They support sending a list of messages, n8n-nodes-openai-structured-outputs only supports on message where you have to construct i json with multiple messages yourself (of course, this is not a blocker, but at least in my opinion the usability of the module provided by n8n is better)

  • I personally like that n8n can be extended by third party nodes very much, i think this is a great feature. However, for core functionality of my processes i would like to use as many nodes provided by n8n itself and i would rather use third party nodes for more exotic things only

vs

I would really like this to be implemented. The OpenAi node is currently handycapped.

Here is someone comparing it to make.com: How do I get Structured Data from OpenAI with n8n as with make.com?

Please read the docs on my service and let me know if it solves your issue. If not perhaps I can work on a N8n integration.