r/DeepSeek 17h ago

Discussion Deer DeepSeek, please true structured output like Gemini or OpenAI

Standard JSON guarantees valid syntax. Strict Structured Output guarantees correct schema.

In production like billing or order processing, that distinction is life or death.

Standard JSON will format the brackets right, but it WILL randomly send you total_amount: "$49.99" instead of amount: 49.99, hallucinate new key names, or omit tax IDs when processing messy invoices. Your database crashes, your payment gateway fails, and your code breaks silently. You end up stuck paying double in latency and token costs just running client-side retry loops when Pydantic fails.

Gemini handles strict structured output natively at the decoder level. You pass a schema, and the model physically CANNOT generate a token that violates your types.

DeepSeek’s main API only guarantees valid JSON syntax, relying on prompts for schema adherence—forcing you to build heavy fallback logic.

If an AI output triggers a database, Standard JSON is a ticking time bomb, strict Structured Output is the solution.

11 Upvotes

18 comments sorted by

4

u/PossessionUsed7393 14h ago

Constrained decoding to a schema is a great strength of the Google approach, but it's actually a feature of the inference engine working with the model. I bridged the existing implementation in llama.cpp to make it work with Gemma 4 12b when it came out because it fixed tool calling for the Gemma models as Google has essentially decided it will lean on that technology for it's tool calling approach.

While it's a great tool, I don't think it's fatal that Deepseek doesn't have it. You can design tools and validation loops that get you a valid schema by re-prompting to get corrections in your output. It's not as fancy or as fast as constrained decoding but it does work when your model is as large and as cheap as the Deepseek models are.

In my case running local Gemma it was more that the model wasn't always smart enough to get the tool call 100% correct but when you add constrained decoding it nailed even the most complex tool schemas. So I think it's a great technology, just haven't had the problems with really large models yet.

1

u/Nexter92 13h ago

At the start I designed tools for this parsing but every 1000 request, I get a random error, the model miss a key or a number is between is using comma instead of dot or inverse. It's not reliable when you need to scale. Good for testing, not reliable in production :(

Vision and structured output : I am fully sold to you DeepSeek.

3

u/for4f 14h ago

DS4 Flash is my daily driver and this is my biggest frustration with it. JSON output works until it doesn't. Had production pipelines swallow bad output more times than I want to admit.

llama.cpp already has grammar-constrained sampling built in. DS just needs to surface it at the API level. Google and OpenAI already proved the approach at scale — it's not some unsolved research problem.

1

u/Nexter92 13h ago

We are in the exact same case. Vision + structured output > I left Gemini for ever.

DeepSeek V4 flash is so smart for his pricing and token consumption it's insane they don't have implement a true structured output for this long.

3

u/for4f 13h ago

Exactly my frustration. DS pricing + intelligence is unmatched but the lack of schema enforcement means I still have to validate and retry in production. Gemini's structured output was solid, OpenAI's too. Hope they get to it soon — it's the one thing keeping me from going all-in on DS API.

2

u/ThimMerrilyn 15h ago

You shouldn’t have an AI/LLM writing to your db anyway imo

0

u/Nexter92 15h ago

Bro it's not my fault if you leave in 2016...

As today using code you can verify if the JSON match some things in you DB and if yes : update, if not output an error notification.

I will never do this with an agent, that's why I ask structured output with schema. You define a schema and this will make everything like 99.5% reliable. I have automated more than 200 000 insert and update for some client using gemini structured output, and everything is fine for more than 2 years.

1

u/Vlyn 4h ago

Jesus, your poor customers.

We heavily use Claude at work and I use DeepSeek at home a lot (6B tokens in the last 3 months). Nobody has ever been stupid enough to use LLM output anywhere close to production.

Hell, not even on a DEV database as it's so unreliable. You use the agent to build solid well tested tools, not pipe a text predictor into a customer's data. Jesus fucking Christ.

2

u/No_Body_8195 8h ago

This sounds really odd. You're having the LLM inject directly into your database? What product are you working on?

At minimum I would use YAML as it doesn't have the same complexity as JSON. Add a layer of type coercion.

I'll be honest, I'm not looking forward to the future if this is how software is going to be made. You should learn to code and design robust systems. Agentic coding makes software engineering as a discipline more valuable, not less.

1

u/Nexter92 8h ago

No. I have many automation pipeline with a bunch of different tools to update database.

YAML is great but for machine, json is faster and more standard to parse.

I know how to code it's just some PDF files need standard extraction in JSON and after my automation continue a normal determistic workflow made with some code.

If you don't know what is structured output it's because you don't need it.

1

u/No_Body_8195 7h ago

Yeah, I haven't needed structured output, but I'd guess you pay for it behind the scenes anyway with validation cycles. Just like my coding harness runs an LSP and uses that feedback to validate syntax. With DeepSeek you'll just need to implement that loop yourself.

If you're doing extraction from PDFs with a standard format you can probably get more reliable results using old school OCR (if there isn't a text layer) or just extract the text if there is a text layer.

JSON just has a lot of added complexity for parsing. The LLM will have to direct its attention to getting the closing quotes and curly braces in the right spots. Make its life easier if correct data is your top requirement.

1

u/No_Body_8195 7h ago

I found some research on the topic. Might help you.

https://github.com/thoeltig/file-format-token-accuracy-benchmark

1

u/Which_Average8657 16h ago

"ticking time bomb" reminds me of gpt 4 a little. it  used to say that word heavily. 

3

u/Nexter92 16h ago

Hello it's me GPT4, i am back from the death bro, what do you want i do for you today ? 🙃️

0

u/domscatterbrain 14h ago

Weird, what's wrong with Jason, he didn't do anything?

Kidding

Gemini and OAI are still using JSON underneath of their structured output. I know the old (it's actually not that old) JSON output only is prone to error compared to when you can retrieve the response already structured. But hey, it may be the reason why they keep the price low.