-
Notifications
You must be signed in to change notification settings - Fork 667
Description
Describe the bug
When using structured output with output.format: json in dotprompt files, the model sometimes wraps the JSON response in markdown code blocks (```json), which causes JSON parsing to fail.
Error message:
data is not valid JSON: invalid character '`' looking for beginning of value
To Reproduce
- Create a dotprompt file with structured output:
---
input:
schema: MyInput
output:
format: json
schema: MyOutput
---
Your prompt text here
- Execute the prompt with
prompt.Execute(ctx, input). - The model occasionally returns the JSON wrapped in backticks:
```json
{"field": "value"}
instead of raw JSON:
{"field": "value"}
- This causes JSON unmarshaling to fail.
Expected behavior
The model should return raw JSON without markdown formatting when output.format: json is specified.
Screenshots
Runtime (please complete the following information):
- OS: macOS
- Version: 15.7.3
Go version:
- go1.26.0 darwin/arm64
Additional context
I'm using Go SDK, but the problem likely affects TS and Python SDKs as well, since they all share the same JSON output instructions.
This behavior was observed with the openai/gpt-4o-mini model. Adding an explicit instruction at the end of the prompt fixes the issue:
Return ONLY raw JSON. Do NOT wrap the response in backticks.
Probably, Genkit should add this instruction automatically.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status