An English system_prompt that includes an example can make the DeepSeek API extract question-and-answer text into JSON; the call must also set response_format to {'type': 'json_object'}. The official documentation also notes that the prompt must contain “json”, a max_tokens value that is too small can cause the JSON to be truncated mid-output, and JSON Output may occasionally return empty content.
Suitable tasks: Extracting fixed question and answer fields from exam questions, question-and-answer records, or similar short text.
Unsuitable tasks: Production data pipelines that require strict JSON Schema, field validation, or complex nested structures; this page only demonstrates basic JSON object output.
Applicable model version: DeepSeek-V4.1-Flash; the API model name is deepseek-flash. The official homepage states that requests using the old names deepseek-v4-flash and deepseek-v4-flash-vision-exp are currently also served by DeepSeek-V4.1-Flash. Official first-call documentation
Applicable client, agent, or API: DeepSeek OpenAI-compatible Chat Completions API; the official example uses the Python OpenAI SDK.
Recommended reasoning tier and parameters: No reasoning tier is specified on this page; set response_format={'type': 'json_object'} and reserve enough max_tokens for the complete JSON.
The following preserves the complete English system prompt from the official example. It includes task instructions, example input, and example JSON output, and can be used directly by replacing the field names and example content.
The user will provide some exam text. Please parse the "question" and "answer" and output them in JSON format.
EXAMPLE INPUT:
Which is the highest mountain in the world? Mount Everest.
EXAMPLE JSON OUTPUT:
{
"question": "Which is the highest mountain in the world?",
"answer": "Mount Everest"
}The user input in the official example:
Which is the longest river in the world? The Nile River.The output in the official example:
{
"question": "Which is the longest river in the world?",
"answer": "The Nile River"
}The call only needs response_format={'type': 'json_object'} added; do not mistake it for a fixed JSON Schema. The client should still parse and validate the returned content.
Use the system prompt above as the system message and the text to be extracted as the user message.
Call Chat Completions with model="deepseek-flash" and set response_format={'type': 'json_object'}.
Confirm that the system or user prompt contains the word “json” and provide an example of the target JSON shape in the prompt.
Set max_tokens appropriately for the output length to prevent the JSON string from being truncated halfway through.
Parse message.content as JSON; if empty content is returned, follow the official recommendation to adjust the prompt and retry, while retaining an empty-content handling branch in the client.
The official documentation states that JSON Output is used to make the model output a valid JSON string.
It is enabled by setting response_format to {'type': 'json_object'}.
The official documentation requires the system or user prompt to contain “json” and provide an example of the target JSON format.
The official documentation requires setting max_tokens appropriately; otherwise, the JSON may be truncated mid-output. The sample code on the page does not explicitly set max_tokens.
The official documentation warns that JSON Output may occasionally return empty content and recommends modifying the prompt to mitigate the issue.
The complete Python example on the page uses “Which is the longest river in the world? The Nile River.” as input, with question and answer as the output fields and “The Nile River” as the answer value.
json_object only expresses valid JSON object output. It does not mean that the server constrains fields, types, or enum values according to a fixed schema; the client still needs to validate field correctness.
The official example only validates a one-sentence question and answer with two string fields. It cannot support an inference that long documents, multiple question-and-answer pairs, or complex nested data will be stable.
A max_tokens value that is too small can cause truncation; the page does not provide a general-purpose number, so leave sufficient headroom based on the input length and target object size.
Empty content is an intermittent issue explicitly disclosed by the official documentation. Modifying the prompt may help, but the page does not provide a retry strategy that guarantees success.
In the DeepSeek OpenAI-compatible API, use model="deepseek-flash" and place the complete system prompt and user input in messages.
Set response_format={'type': 'json_object'} and set max_tokens based on the expected output length.
Parse response.choices[0].message.content and check whether it contains the two keys and corresponding values from the official example.
Also test with a smaller max_tokens value to observe the truncation risk; retain a failure record for empty content and do not treat one successful run as proof of stability.
The collection date is 2026-09-16; use the official first-call documentation current page as the source of truth for the model name and version mapping.
DeepSeek V4.1 Flash