Content Navigation
1. What is the Problem?
Recently, I’ve been working on a task that involves using large language models to generate “deterministic” data. During this process, I encountered issues with output instability. For example, the data format and units generated varied each time, requiring additional manual intervention to adjust the format or content. This reduces efficiency and leads to difficulties in subsequent processing. After some experimentation, I feel the results are quite good, and I’m sharing them here.
2. Three Elements of Structured Constraints
-
Data Determinism
-
Field Locking: “Output in JSON format, must include the following fields: {field_name: type_description}”
-
Data Validation: “Numerical values must be within the range of 0-100, time format must be MM-DD-YYYY”
-
Example:
Generate parameters for 3 fictional electronic products: [Requirements] - Include model/price/weight fields - Price in USD and rounded to two decimal places - Present in a Markdown table
-
-
Format Determinism
-
Dual Constraint: “First wrap with XML tags, then convert the entire thing to Base64 encoding”
-
Separator Reinforcement: “Use『||』to separate different paragraphs, use “” to mark professional terms”
-
Example:
Output ancient poetry analysis: 1. Enclose the original text with "" 2. Add ◆ symbol before each line's annotation 3. Leave two blank lines at the end for the appreciation summary
-
-
Style Determinism
-
Corpus Anchoring: “Imitate the writing style of The Economist’s 2019 technology column”
-
Quantitative Metrics: “Sentence length should not exceed 15 characters, each paragraph should contain 3 idioms”
-
Example:
Write a refrigerator instruction manual: - Adopt GB/T 5296.2 national standard - Mark technical parameters in KaiTi font - Warning statements must be preceded by the ⚠️ symbol
-
3. 3. Advanced Control Techniques
-
Meta-Instruction Embedding Method Insert a self-check mechanism in the prompt:
[System] You are a generator that strictly adheres to rules. Before outputting, please confirm in order: 1. Whether all required fields are included 2. Whether the number format conforms to the thousands separator notation 3. Whether any separators are missing
-
Phased Generation Method Break down complex tasks into a deterministic pipeline:
Step 1: Generate 5 candidate titles (numbered numerically) Step 2: Evaluate based on "attractiveness score (1-5)/keyword density/length" Step 3: Output the title with the highest score, along with the reason for selection
-
Physical Constraint Method Forcibly standardize output through technical means:
Output must satisfy: - Total character count = 258±3 - Contains exactly 3 emojis - Each line ends with a semicolon;
4. Engineering Solutions
-
Hybrid Validation System
Hybrid Validation System -
Determinism Enhancement Strategies
-
Temperature Parameter: Set temperature to below 0.3 (0 is completely deterministic)
-
Model Selection: Prioritize GPT-4 over GPT-3.5 (instruction following capability +40%)
-
Dual Validation: Have another model check the output for compliance
-
-
Template Injection Technique Pre-embed structure using placeholders:
Generate meeting minutes: --- [Subject]: {{auto-fill}} Attendees: {{list_format}} Resolutions: 1. {{brief_description_not_exceeding_8_chars}} ▸ Implementation details: {{semicolon_separated}} 2. {{same_as_above}} ---
5. Typical Scenario Case Study
Medical Report Generation
[System Instruction] You are a radiology AI assistant, strictly adhering to the following requirements: 1. Divide the diagnostic description into "Imaging Findings/Diagnostic Opinion" two parts 2. Use medical terminology (ICD-11 codes) 3. Bold key indicators [Input] CT scan shows a 2.1cm nodule in the middle lobe of the right lung, with spiculated margins [Output] Imaging Findings: A round-like high-density shadow (ICD-11: ME24.3) is seen in the middle lobe of the right lung, with a maximum diameter of 21mm, spiculated margins, and adjacent pleural traction. Diagnostic Opinion: High probability of peripheral lung cancer (Bosniak Class Ⅳ), biopsy recommended (refer to NCCN guidelines v3.2023).
6. Effect Evaluation Metrics
Dimension | Control Method | Error Rate Reduction |
---|---|---|
Data Accuracy | Field Locking + Regex Validation | 92% |
Format Compliance | Template Engine + Syntax Parser | 87% |
Style Consistency | Corpus Comparison + Similarity Analysis | 79% |
Through this set of methods, we successfully reduced the output fluctuation rate of a financial briefing generation system from 38% to 5.7%, and the format error rate from 22 times/thousand characters to 1.3 times/thousand characters. The key is to establish a complete constraint chain from instruction design to post-processing, allowing the large model to achieve a precise balance between free creation and rule adherence.