Guided JSON in vLLM: Fixing Invalid LLM JSON on DGX Spark (Nemotron Nano Omni Rerun)
AI engineering is just process engineering. — Greg Alton
My last DGX Spark recipe ended with three fixes and a promise to rerun the experiment. The model was fast, but 12% of its replies were broken JSON, and it mostly repeated the counter numbers back to me.
So I replayed a saved production-style SIP server log, 1.6 million lines, through two setups on my DGX Spark: the old prompt, and guided JSON with a better prompt. Same model, same 42 windows. I bought the Spark to learn by doing, and this run taught me something I didn't expect: fixing the format was easy, but the new prompt changed what the model thought its job was.
Prefer to watch? Catch the quick video on YouTube.
- Time
- About 20 minutes
- Checked
If a button name on the screen does not match this guide, follow the action. These products rename buttons often. This is an advanced guide: it uses code, and each technical term is explained the first time it appears. Model names and prices change, so check the linked docs before you ship.
Steps
What I promised, and how I tested it
In the hybrid log-watching recipe, the counters-plus-model pattern worked, but the model had two bad habits: 12% of its replies were invalid JSON, and it mostly repeated the counter numbers back to me. I ended with three fixes and a promise to rerun it. This is the rerun.
- The log: a saved production-style SIP server log, 1,645,716 lines. I replayed the saved file instead of streaming live, so both setups saw identical input. Raw lines never left the Spark.
- The model: Nemotron 3 Nano Omni (NVFP4), served by vLLM 0.20 on the Spark, with thinking off, temperature 0, and a 300-token cap.
- The counters: Fix 1, the level-aware regex counters, read every line.
- Setup A: the original prompt, with no structured output. It asks for
issuesandhealth. - Setup B: guided JSON (Fix 2) plus the judgment prompt (Fix 3).
- The windows: both setups got the same 42 windows from the file, one check every 120 seconds of log time.
The October run is the baseline for context only. It was a live 15-minute stream with screenshots and a word-based error counter, so it isn't a perfect twin. The fair comparison is A vs B.
Fix 2 in practice: the guided JSON request
This is the request setup B sent. The
response_formatblock is the whole trick: vLLM constrains decoding to the schema, so the model can't produce broken JSON.import requests SCHEMA = { "type": "object", "properties": { "verdict": {"type": "string", "enum": ["ignore", "watch", "page"]}, "likely_cause": {"type": "string"}, "new_pattern": {"type": "string"}, "next_check": {"type": "string"}, }, "required": ["verdict", "likely_cause", "new_pattern", "next_check"], "additionalProperties": False, } r = requests.post("http://localhost:8000/v1/chat/completions", json={ "model": "your-model", "messages": [{"role": "user", "content": prompt}], "response_format": { "type": "json_schema", "json_schema": {"name": "verdict", "schema": SCHEMA, "strict": True}, }, "chat_template_kwargs": {"enable_thinking": False}, "temperature": 0, "max_tokens": 300, }, timeout=60)I had a fallback ready in case the server rejected
json_schema. It never needed it: all 42 setup B calls went through in schema mode.Fix 3 in practice: the judgment prompt
The counter totals go in as context, followed by one plain instruction. Here's the prompt shape with the log sample removed:
You are a secondary judge for a SIP proxy log watcher. Cheap regex counters already counted every line. Here are their totals (context only): {counter totals as JSON} Do not repeat these numbers. Trigger: periodic. Using the log sample, answer with judgment the counters cannot give: 1) Is this new relative to normal traffic? 2) What is the likely cause (one client retrying vs many failing, etc.)? 3) What should a human check next? 4) Is there a pattern worth a new counter? If yes, put a concrete Python/PCRE-style regex in new_pattern; otherwise put an empty string. Return ONLY JSON matching the schema. --- LOG SAMPLE --- {recent lines}To score the echo problem, I counted a reply as an echo when most of the numbers in it (70% or more) were just the counter numbers repeated back.
The results
Measure October baseline Setup A (old prompt) Setup B (guided JSON + Fix 3) Lines about 292k (live) 1,645,716 1,645,716 Model calls 85 42 42 Invalid JSON about 12% 0% 0% Replies that echo the counters frequent 0% 0% Mean latency 1.12 s 0.57 s 1.41 s Latency range 0.63–5.7 s 0.51–1.43 s 1.15–1.94 s Regexes suggested none 0 1 Invalid JSON went from about 12% to 0%, and the echo went away. Setup B is about 0.8 seconds slower per call, because the replies are longer and the decoder follows the schema. That still sits inside the old 0.75–2.35 s trip-to-verdict range, so it's a fair price for never dropping an alert to broken JSON.
Same window, side by side:
// Setup A {"issues": [], "health": "ok"} // Setup B {"verdict": "watch", "likely_cause": "single client retrying after loop detection", "new_pattern": "", "next_check": "Check for repeated 482 Loop Detected responses from the same client and verify NAT/routing configuration causing circular path"}Setup B is answering the question I actually asked: what's the likely cause, and what should a human check next?
The one regex it suggested: keep, with a caveat
I wanted the model to teach the cheap layer new tricks. In 42 calls, setup B suggested exactly one pattern, in one reply:
.*Loop Detected.*I scored it against the whole file:
Check Result Lines matched 47,139 of 1,645,716 (2.9%) Sampled matches that were right 50 of 50 Scan time 3.75 s for the whole file (about 2.3 µs a line) Verdict: keep, with a caveat. It found the right lines, but the
.*on both ends adds nothing except work, becausere.searchalready looks anywhere in the line. I'd promote the tighter form:LOOP = re.compile(r"482 Loop Detected")At 2.9% of all lines, it's a good counter and a noisy alert. Count it, and alert on a jump, not on every hit.
Real logs don't come with an answer key, so "50 of 50" comes from labelling a sample of matches, not from ground truth. Treat it as an estimate.
What went wrong (and the fixes)
I promised honest numbers, so here are the parts that didn't go to plan.
- No real alert ever fired. The saved capture turned out to be almost all debug-level lines. The level-aware counters found 0 errors and 0 warnings in 1.65 million lines, so all 42 windows were routine periodic checks. Fix: pick a log that contains the failure you're trying to catch. I'll find a capture with a real error burst for the next run.
- Every quiet window got "watch". On the same calm windows, setup A said
okevery time, and setup B saidwatchevery time. The schema makes B pick a verdict, and it never choseignore, even though that was allowed. A loop-detection retry looks interesting, so it kept flagging it. Fix: renameignoretookso it matches the model's own word, add "If nothing is new, answer ok" to the prompt, and add a quiet-window rule in code: if no counter tripped, log the verdict but don't escalate awatch. - The model copied client IPs into
next_check. It sometimes repeated addresses from the sample lines. Fix: scrub model output (IPs, phone numbers, user names) before you log it, share it, or send it to chat. It's a reply from your own model, but it's built from your raw data. - My level regex missed lines at first. On the real lines, the text runs straight into the level tag with no space, so a pattern that expects a space before the level finds nothing. Fix: allow zero or more spaces:
Test it on a handful of your own lines before you trust it.import re LEVELS = r"DEBUG|INFO|NOTICE|WARN(?:ING)?|ERROR|CRIT(?:ICAL)?|FATAL" # \s* (not \s+) accepts the tag with or without a space in front of it. LEVEL = re.compile(rf"^\S+\s+\S+?\s*\[?({LEVELS})\]?(?=[\s:\]\-]|$)", re.I) - The echo test was easy this time. With quiet windows and zero counts, there wasn't much to echo. I'm calling the echo fixed on this log, but not proven on a busy one.
- It's slower. About 0.8 s a call slower, as noted above. That's fine for a periodic judge, but don't put it in a hot loop.
The takeaway
Guided JSON is the easy win. One
response_formatblock took invalid replies from about 12% to 0%, with no retries and no fallback needed. If you parse model output in code, turn it on.The prompt changes the job, not just the format. The same model on the same windows said "ok" with the old prompt and "watch, here's why, check this next" with the new one. That's more useful, but it needs a way to say "nothing new" or it will cry wolf. The model also suggested one regex, and it was right. That's a small start on the goal of the model teaching the counters.
Next, I'll run it on a log with a real error burst and the
okverdict added. Follow the DGX Spark section for that one.Want to try this without buying a DGX Spark? GPUwerk.com rents dedicated DGX Spark time by the minute, and it looks like an inexpensive way to try before you buy. (GPUwerk is not a sponsor. Samuel from GPUwerk asked the question that started this rerun.)
Tips
Replay a saved log when comparing setups. Live traffic changes under you; a saved file gives every setup identical windows.
Set
strict: trueandadditionalProperties: falsein the schema, and still keep a non-model fallback alert in case the model server is down.Drop the
.*at the ends of a suggested regex.re.searchalready matches anywhere, so the wrappers only cost time.Scrub model output before it leaves the box. The model will happily quote addresses from the sample you gave it.
Turn thinking off for a short JSON judge. You want a fast verdict, not a long reasoning trace.
Common questions
Does guided JSON make the model smarter?
No. It guarantees the shape of the reply, not the quality of the judgment. In this run, the shape was perfect every time, and the judgment needed a prompt fix: it said "watch" on every quiet window.
Why did setup A also get 0% invalid JSON?
Setup A gave short, simple replies on quiet windows ({"issues": [], "health": "ok"}), which are hard to break. October's 12% came from a busier live stream with 12 counter trips and screenshot calls. Guided JSON is what makes 0% a guarantee instead of luck.
Is 0.8 seconds extra a problem?
Not for this job. The counters raise the alert instantly; the model adds context a second or two later. Setup B's slowest call, 1.94 s, was still inside the original trip-to-verdict range.
Should I ship the model's regex as-is?
No. Score it on your own log first: count the hits, check a sample by hand, and time the scan. Then tighten it. Here, .*Loop Detected.* became 482 Loop Detected.
More guides
AdvancedClaudeBuilding
Call the Claude API in Python and cut costs with prompt caching
Get an API key, make your first Claude Messages API call in Python, then add prompt caching so repeated long prompts cost less and run faster.
About 30 minutes using Claude Console, Claude API docs
AdvancedClaudeBuilding
Build your first MCP server in Python and use it in Claude Desktop
Write a small Model Context Protocol server with the official Python SDK, expose a tool, and connect it to Claude Desktop so Claude can call it.
About 35 minutes using MCP docs, Claude Desktop
AdvancedGrokBuilding
Build a simple RAG pipeline with the xAI Grok API
Answer questions from your own documents: split them into chunks, retrieve the best matches, and have Grok answer with citations via the xAI API.
About 40 minutes using xAI API docs, xAI Console