Summary: The JSON returned by Hy4 Flash and DeepSeek V4.1 Flash both parse cleanly, yet field validation still fails. The reason is that “parseable” only clears the first gate. This article explains the differences in request parameters between the two first-party APIs and how to use the same validator to complete acceptance before ingestion.
Bottom line up front: If JSON parses, that only means the text conforms to JSON syntax. Whether fields are all present, types are correct, enums are valid, and content matches the source are two separate gates: the schema gate and the business gate. The consistent difference between the two vendors is on the request side. According to Tencent Cloud’s official documentation, Hy4 Flash’s Chat Completions path can carry a schema in the request via response_format.type = json_schema. DeepSeek V4.1 Flash’s native API accepts only two values, text and json_object; structural constraints can only go in the prompt, and enforcement is the application’s responsibility. Whichever vendor you connect to, the application should independently run full contract validation before ingestion. During migration, the validator and test inputs stay the same; you only replace the request adapter and the finish reason mapping.
The protocol facts in this article were verified on 2026-11-25 (Beijing time) against the official documentation for Tencent Cloud TokenHub and DeepSeek. The ticket examples and fixtures in this article are local examples written to illustrate the contract and do not represent measured results.

Knowledge Map: The Full Field-Validation Flow for Hy4 Flash vs DeepSeek V4.1 Flash

Figure note: The difference between the two vendors shows up only at the request entry points at the very top, namely 1.1 and 1.2. From Section 2 onward, both paths share the same contract, the same validator, and the same set of fixtures. Every gate has a clear destination when it fails: either a limited retry or a handoff to manual review — never a direct database write.
Index: How to Read This Article
- Section 1 compares the two vendors’ native protocols and explains what the request layer can enforce, plus which responsibilities stay with the application.
- Section 2 defines the shared work-order extraction contract and the two request adapters; every check in the sections that follow rests on that contract.
- Section 3 follows the execution order: record the termination reason first, then clear the three gates — format, schema, business — in sequence, and finally the retry and the database write. This is the heart of the article; read 3.1 through 3.5 in order.
- Section 4 uses fixed fixtures to verify the migration and gives three counterexamples for pinpointing which stage went wrong. When you’re running a switch-over regression, you can consult it on its own.
- Section 5 is an acceptance checklist you can run as-is.
To Know: Terms You’ll Need
| Term | Plain-English explanation |
|---|---|
response_format |
The parameter in a Chat Completions request that controls output format; different vendors support different values |
json_schema mode |
Carries a JSON Schema inside the request to describe the expected structure |
json_object mode |
Only requires the output to be a JSON object; the structural agreement has to be written into the prompt |
finish_reason |
The reason generation ended. stop means a normal finish; length means the length limit was hit |
properties / required |
The former describes the rules that fields already present must satisfy; only the latter requires a key to exist |
additionalProperties |
Controls whether an object may contain undeclared keys. Allowed by default |
| schema dialect | The specification version of JSON Schema, e.g. Draft 2020-12. Keyword behavior differs between versions |
| Idempotency key | A unique key derived from the source record and the contract version, so retries don’t write twice |
1. Hy4 Flash vs DeepSeek V4.1 Flash: Request Protocol Differences
1.1 Hy4 Flash: the json_schema request shape
Tencent Cloud TokenHub’s model list explicitly lists structured output as a capability of hy4-flash. In the structured output subsection of the Hunyuan calling guide for POST https://tokenhub.tencentmaas.com/v1/chat/completions, the documentation demonstrates using response_format.type = json_schema together with json_schema.name and json_schema.schema. The inner schema example includes type, properties, required, and array element types.
One thing to note: the model used in the guide’s example is hy4, not hy4-flash. So the evidence in this article comes in two parts: Flash supports structured output, based on the model catalog; the request shape references the guide example under the same path. Applying this shape to hy4-flash is an inference drawn from these two documents. Before integrating, it’s worth verifying the actual behavior with a small sample.
1.2 DeepSeek V4.1 Flash: json_object and the Contract in the Prompt
Direct DeepSeek access uses POST https://api.deepseek.com/chat/completions, with the model set to deepseek-flash. According to the official model page, this alias currently maps to DeepSeek-V4.1-Flash-1017. The API reference limits response_format.type to text and json_object; there is no parameter for carrying a schema in the request.
When using json_object, the official JSON Output guide requires the word “JSON” to appear in the system message or user message, along with an example of the target structure, and you should set max_tokens according to the task’s needs. This guidance applies only to DeepSeek’s first-party API. If the same model is invoked through another protocol or platform, consult that platform’s API reference.
DeepSeek’s documentation also notes two outcomes that are easy to misjudge:
- When the model output can’t be recognized as JSON, the service may replace the content with spaces. So even if
finish_reason=stop, what you get may be blank. finish_reason=lengthmeans the content may have been truncated, either because the generation budget was insufficient or because the context length limit was reached. In this case, adjust the effective budget and input length first.
In addition, for streaming integration, wait until content aggregation is complete and the termination information has fully arrived before parsing. Even candidate values from a normal completion must still go through application-side validation.
1.3 Hy4 Flash vs DeepSeek V4.1 Flash: Validation Responsibility Comparison

Figure note: The difference between the two lies in the first three rows—request parameters, where the structural contract lives, and special outcomes. The fourth row is identical: both paths require full validation on the application side. The DeepSeek path leaves structural validation and enforcement entirely to the application; even when the Tencent path includes a schema in the request, the application should still independently validate the complete contract.
| Comparison item | Hy4 Flash (Tencent first-party) | DeepSeek V4.1 Flash (first-party) | Evidence type |
|---|---|---|---|
| Endpoint | tokenhub.tencentmaas.com/v1/chat/completions |
api.deepseek.com/chat/completions |
Official documentation |
| Model field | hy4-flash (guide example uses hy4) |
deepseek-flash |
Model catalog / model page |
response_format.type |
Example uses json_schema |
Only text, json_object |
Guide example / API reference |
| Where the structural contract lives | json_schema.schema |
Instructions and examples in the prompt | Example / official guide |
| Blank output and truncation | Not covered by materials in this article | May return blank; length may indicate truncation |
DeepSeek official notice |
| Application-side validation | Independent full validation | Independent full validation, responsible for structural enforcement | Engineering recommendation in this article |
2. Shared Business Contracts and the Hy4 Flash / DeepSeek V4.1 Flash Adapters
2.1 The Ticket Extraction Contract
Let’s use ticket extraction as our example. The stored object has three fields: a string case_id, a status whose only legal values are open or closed, and an array called evidence. Each element in that array carries source and quote. You need to declare required fields on the root object and on the nested object separately, because required at the root doesn’t reach the elements inside an array.
How you handle missing evidence has to be written down as an explicit policy. You can allow an empty array and push the record into a review queue, or you can demand at least one piece of evidence and hand the whole task to a human when it’s absent. Whichever policy you pick needs to show up in three places — the prompt, the validation rules, and the stored status — otherwise the model, the validator, and the database will each handle the same situation according to a different assumption.
CONTRACT_VERSION = "case-extract/v1" # example version number
CASE_SCHEMA = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"case_id": {"type": "string"},
"status": {"type": "string", "enum": ["open", "closed"]},
"evidence": {
"type": "array",
"items": {
"type": "object",
"properties": {
"source": {"type": "string"},
"quote": {"type": "string"}
},
"required": ["source", "quote"],
"additionalProperties": False
}
}
},
"required": ["case_id", "status", "evidence"],
"additionalProperties": False
}
This schema goes with a closed structure — additionalProperties: false rejects any unknown keys — and it allows evidence to be an empty array, leaving it to the business layer to route such records for review. These are contract decisions made in the example; the actual trade-offs are yours to make on your receiving end.
2.2 Two Request Adapters
The Tencent path sends a trimmed-down schema along with the request. The DeepSeek path states the field conventions in the prompt and provides input/output examples. Both share the same CASE_SCHEMA as the basis for storage validation.
def build_hy4_flash_body(text: str) -> dict:
# request shape follows the structured output example in the Hunyuan API guide (example model is hy4)
return {
"model": "hy4-flash",
"messages": [{"role": "user", "content": f"从以下工单中抽取信息:\n{text}"}],
"response_format": {
"type": "json_schema",
"json_schema": {"name": "case_extract", "schema": CASE_SCHEMA}
}
}
def build_deepseek_flash_body(text: str) -> dict:
system = (
"只输出 JSON 对象,字段:case_id(字符串)、status(只能是 open 或 closed)、"
"evidence(数组,元素含 source 与 quote)。原文无证据时 evidence 为 []。\n"
'示例输出:{"case_id":"C17","status":"open",'
'"evidence":[{"source":"ticket","quote":"用户反馈无法登录"}]}'
)
return {
"model": "deepseek-flash",
"messages": [{"role": "system", "content": system},
{"role": "user", "content": text}],
"response_format": {"type": "json_object"},
"max_tokens": 1024 # set according to your task estimate
}
For authentication and other request headers, defer to each provider’s own official docs — what’s shown here is only the structure-related part of the request body.
3. Three Gates for Field Validation After JSON Parsing

Figure note: Each layer only handles the type of error it is responsible for. “Parseable” only means it passed 3.2; field validation failures happen at 3.3 or 3.4. Categorizing errors by layer lets you later judge whether to change the prompt, change the source data, or hand it off to a human.
3.1 Record Termination Reasons and Classify Exits
After the request finishes, first record the endpoint, model identifier, contract version, request identifier, and termination reason. Read the output only from the assistant’s body text. If the response also contains reasoning fields, you can preserve them as the protocol requires, but the parser should only handle the body text. Missing, blank, and truncated should be recorded as three distinct categories—that way, when you look at logs, you can tell budget issues, empty-content issues, and field issues apart.
def classify_exit(finish_reason, content):
if content is None:
return "missing"
if finish_reason == "length":
return "truncated" # Check budget and input length first
if content.strip() == "":
return "blank" # DeepSeek docs note that stop can also be blank
return "has_text"
3.2 Format Gate: Strict Parsing
Parse the body text strictly exactly once, then check whether the top level is an object. When you encounter duplicate keys, you should actively reject them. The reason is that runtimes in different languages may take either the first value or the last value for duplicate keys, so the same piece of text can produce different results across different services.
import json
def _reject_duplicates(pairs):
obj = {}
for k, v in pairs:
if k in obj:
raise ValueError(f"duplicate key: {k}")
obj[k] = v
return obj
def strict_parse(content: str) -> dict:
data = json.loads(content, object_pairs_hook=_reject_duplicates)
if not isinstance(data, dict):
raise ValueError("top-level is not an object")
return data
3.3 Schema Gates: Types, Required Fields, Enums, and Extra Fields
Most “parses but fails validation” problems come from this layer. properties only constrains fields that are already present; only required makes a key mandatory. A key being present with a value of null and a key not existing at all are two different cases. Whether to accept null needs to be declared separately in the contract. Objects in JSON Schema allow extra keys by default. If you want a closed structure, the receiver needs to declare that explicitly.
Validation errors should record the JSON path and rule category—for example, missing /evidence/0/quote, or /status not being in the enum. Also pin the schema dialect and include the dialect in the version record.
from jsonschema import Draft202012Validator
validator = Draft202012Validator(CASE_SCHEMA)
def schema_errors(data: dict) -> list[dict]:
return [
{"path": "/" + "/".join(str(p) for p in e.absolute_path),
"rule": e.validator, # required / enum / type / additionalProperties
"contract": CONTRACT_VERSION}
for e in validator.iter_errors(data)
]
Look at the local counterexamples: {"case_id":"C17","status":"open"} parses fine, but it reports a required error on the root object because evidence is missing. {"case_id":"C17","status":"处理中","evidence":[]} reports an enum error at /status; whether the empty array is valid depends on the strategy selected in 2.1.
3.4 Business gate: domain rules
Only objects that pass schema validation make it into domain-rule checks. Common rules include: the source must appear in the input, fields must be consistent with each other, and amounts must be stored at a consistent precision or in the smallest currency unit. If the input comes from an external ticketing system, the record key should be based on trusted server-side metadata, and you should also check whether the ID echoed back by the model matches the input. No matter how structurally complete it is, if the key points to another record, it must be blocked before writing to the database.
Here’s another example that’s structurally complete but wrong from a business perspective: a supplier extraction record has a date, currency, and amount, but the tax-inclusive total was placed in the tax-exclusive field. Domain errors can use the same path format as type errors, but the error type should be recorded separately.
def domain_errors(data: dict, source_text: str, trusted_case_id: str) -> list[dict]:
errs = []
if data["case_id"] != trusted_case_id:
errs.append({"path": "/case_id", "rule": "domain:id_mismatch"})
for i, ev in enumerate(data["evidence"]):
if ev["quote"] not in source_text:
errs.append({"path": f"/evidence/{i}/quote", "rule": "domain:quote_not_in_source"})
if not data["evidence"]:
errs.append({"path": "/evidence", "rule": "domain:needs_review"}) # route to review per policy
return errs
3.5 Limited retries and idempotent database writes
Blank bodies, correctable format errors, and insufficient budget should each have their own retry cap. For results with missing fields, you can use the error paths returned by the validator as constraints for the next generation, along with the same original material and business conventions. Once the cap is reached, leave the ticket in the review queue.
When writing to the database, use an idempotency key derived from the source record and contract version to avoid inserting the same result twice during retries. Failure metrics should keep only aggregate numbers and redacted paths, so you can measure both the payoff from validation and the cost of added retries.
| Exit category | Typical signal | First response | After hitting the cap |
|---|---|---|---|
| Truncation | finish_reason=length |
Adjust max_tokens or shorten the input |
Manual review |
| Blank | Body is all whitespace | Check the JSON instructions and examples in the prompt | Manual review |
| Format error | Parse failure, duplicate keys | Retry with the same materials | Manual review |
| Schema error | required / enum / type |
Retry with the error paths | Manual review |
| Domain error | ID mismatch, quote not in source | Depending on the case, fix source data or route to manual review | Manual review |
4. Validating the Hy4 Flash → DeepSeek V4.1 Flash Migration with Fixed Fixtures
4.1 Fixture List
Start by running each adapter through one round using purely local response fixtures. Comparing the raw payload against the application object field by field lets you tell whether the model dropped a field or the middleware lost a key. Some serialization layers omit null values, and some languages initialize absent fields to zero. So before writing to storage, validate the raw object first, then apply the default-value mapping you’ve explicitly defined.
| Fixture | What it constructs | Expected interception layer (per the 2.1 contract) |
|---|---|---|
| Fully populated | All three fields plus complete evidence | Pass |
| Payload missing evidence | evidence: [] |
3.4 → pending review |
| Enum near-synonym | status: "处理中" |
3.3 enum |
| Missing field inside array | Evidence element missing quote |
3.3 /evidence/0/quote |
| Unknown extra field | Extra priority |
3.3 additionalProperties |
| Explicit null | case_id: null |
3.3 type |
| Malformed | Missing closing brace | 3.2 |
| Blank payload | Spaces only | 3.1 blank |
| Hit length limit | finish_reason=length |
3.1 truncated |
The “Expected” column is what the validator ought to do — it isn’t the model’s measured rate. To compare behavior before and after the switch, track separate counts: successful parses, schema passes, domain passes, manual handoffs, and reruns. Real rates have to come from labeled production data measured under fixed conditions.
If the business allows default values, tag the source of each default per the contract so it can be audited. Also test whether defaults for fields like dates and currencies end up masking gaps in the original payload.
4.2 Three Counterexamples for Isolating the Faulty Stage
- Contract version switch: Historical tickets used to allow Chinese status values, while the current rules require an English enum. Old data should still be read back under the original rules, and tested separately from the post-switch write rules. When the same event shows up in the queue again, the retry must reuse the original contract version; a different contract should be treated as a separate ingestion job.
- Swapped identifiers: A record contains both a task ID and a subtask ID, and both are strings, so every type check passes. The application still has to verify each ID against the source material separately to avoid a column-mapping swap.
- Conversion hiding a type error: The model returned a number, and the client converted it to a string before validating — so a type error that should have been counted disappeared. The right order is to strictly validate the value exactly as parsed, and only then run the deterministic business conversion.
These three counterexamples show that switching the format mode from json_object to json_schema only changes how much structural constraint the request layer can absorb. The business threshold in section 3.4 and these conversion-ordering issues always remain the application’s responsibility.
5. Acceptance Checklist
Before going live or switching providers, confirm each item in the following order:
- Logs can distinguish the three exit types — missing, blank, and truncated — and carry the contract version and request identifier.
- The parser rejects duplicate keys and non-object top-level values.
- The validator pins the dialect, the root object and nested objects each declare
required, and both the handling ofnulland the policy for additional keys are documented. - Domain rules cross-check trusted IDs and source quotes, and error types are logged separately from schema errors.
- Re-runs have an attempt limit; once the limit is hit, the case goes to human review, and database writes use idempotency keys.
- The nine fixtures from Section 4.1 land in the expected interception layer under both adapters.
Only when all six items pass does it show that the acceptance results across the two paths under the same contract are consistent — and only then is there a comparable basis for discussing model performance.
References
- Tencent Cloud TokenHub Model List:
hy4-flashstructured output capability- Link:
cloud.tencent.com/document/product/1823/130051
- Link:
- Hunyuan Invocation Guide: structured output request shape (example model
hy4)- Link:
cloud.tencent.com/document/product/1823/132252
- Link:
- DeepSeek Chat Completions API Reference:
response_formatvalues and streaming notes- Link:
api-docs.deepseek.com/api/create-chat-completion
- Link:
- DeepSeek JSON Output Guide: prompting requirements and notes on blank/truncated output
- Link:
api-docs.deepseek.com/guides/json_mode
- Link:
- DeepSeek Models and Pricing: the version corresponding to the
deepseek-flashalias- Link:
api-docs.deepseek.com/quick_start/pricing
- Link:
- JSON Schema Object Reference:
properties,required, and additional properties- Link:
json-schema.org/understanding-json-schema/reference/object
- Link:
