How `material_gate.py` Checks for Required Disclosure Materials in Patent Applications
The material_gate.py script verifies required disclosure materials by scanning the case directory for a disclosure document, detecting the patent type from its content, and validating type-specific assets including schemas, figure plans, and visual assets before allowing the application pipeline to proceed.
The material_gate.py script in handsomestWei/patent-disclosure-skill serves as the entry checkpoint for patent application workflows. Located at skills/patent-application/tools/material_gate.py, it performs a deterministic validation sequence to check for required disclosure materials, ensuring that invention, utility model, and design patent cases contain every necessary file before downstream processing begins.
Locate the Disclosure Document
The script initiates the check by locating the disclosure document within the case directory. If the user provides the --disclosure argument, the script uses that path directly. Otherwise, it automatically scans for files matching .md or .docx extensions, preferring those that match a timestamp pattern or contain the "技术交底书" heading.
This search logic is implemented in the find_disclosure function (lines 83‑101). The function iterates through the case directory, filtering candidates by extension and content markers to identify the authoritative disclosure file.
# From skills/patent-application/tools/material_gate.py
def find_disclosure(case_dir: Path, hint: Optional[Path] = None) -> Optional[Path]:
# Lines 83-101: Searches for .md/.docx files with timestamp patterns
# or "技术交底书" headers when no explicit --disclosure path is given
pass
Detect the Patent Type from Content
Once the disclosure document is located, the script extracts the patent type declaration. For markdown disclosures, the detect_type_from_disclosure function (lines 104‑115) uses the PATENT_TYPE_LINE regular expression to find lines declaring the type (e.g., "专利类型: 发明").
The extracted Chinese label is normalized through the TYPE_ALIASES mapping to one of three canonical types:
invention(发明)utility_model(实用新型)design(外观设计)
This normalization ensures that variations in user input resolve to standardized categories for subsequent validation logic.
Gather Supporting Assets and Schemas
After determining the patent type, the script collects supporting files using the _first_file helper against predefined name sets stored in SCHEMA_NAMES (lines 41‑45). The script specifically looks for:
- Structure schema:
structure_schema.yamlor.json(for utility models) - Appearance schema:
appearance_schema.yamlor.json(for design patents) - Figure plan:
figure_plan.yamlor.json
If a figure plan exists, the script parses it via yaml.safe_load or json.loads and extracts figures marked with use_in_disclosure=True using the in_disclosure_figures function (lines 28‑34).
# Schema name definitions from lines 41-45
SCHEMA_NAMES = {
"structure_schema": ["structure_schema.yaml", "structure_schema.json"],
"appearance_schema": ["appearance_schema.yaml", "appearance_schema.json"],
"figure_plan": ["figure_plan.yaml", "figure_plan.json"]
}
Validate Type-Specific Requirements
The core validation logic resides in the check_case function (lines 136‑225), which applies different rules based on the detected patent type to check for required disclosure materials:
Utility Model Patents
- Requires
structure_schemaandfigure_plan - Must reference at least one lineart asset in the figure plan
- Missing items reported as:
structure_schema,figure_plan,lineart
Design Patents
- Requires
appearance_schema,figure_plan, and at least one lineart - Must include photo assets (
photo_cleanorphoto_scene) - Missing items reported as:
appearance_schema,figure_plan,lineart,photo
Invention Patents
- No additional schema requirements beyond the disclosure document itself
- Presence of a valid disclosure file is sufficient
The function constructs a result dictionary containing ok (boolean pass/fail), type (canonical patent type), missing (list of gaps), files (resolved paths), and counts for lineart and photo assets.
Command-Line Interface and Exit Codes
The script provides a command-line interface for gate-checking case directories before pipeline execution.
python tools/material_gate.py --case-dir outputs/案件_XYZ
# Optional overrides:
# --disclosure outputs/案件_XYZ/交底书_20240101120000.md
# --type utility_model
On execution, the script prints a one-line status string formatted by the _kv helper (lines 36‑48):
APPLICATION_GATE: ok=1 type=utility_model missing=- lineart=2 photo=0 ...
Exit codes follow Unix conventions:
0— All required materials are present and valid2— Validation failed (missing files, unreadable schemas, ambiguous patent type, or unsupported configurations)
Programmatic Integration
You can import the validation logic directly into Python workflows to check for required disclosure materials programmatically.
from pathlib import Path
from skills.patent_application.tools.material_gate import check_case
case_path = Path("outputs/案件_XYZ")
result = check_case(case_path) # Auto-detects disclosure and patent type
if result["ok"]:
print(f"Patent type: {result['type']}")
print(f"Lineart assets: {result['lineart']}")
else:
print("Missing materials:", result["missing"])
The returned dictionary mirrors the command-line output structure, enabling fine-grained diagnostics for automation scripts and CI/CD pipelines.
Summary
material_gate.pyacts as the gatekeeper for patent application cases in thehandsomestWei/patent-disclosure-skillrepository.- The script locates disclosure documents automatically or via explicit
--disclosureflags. - Patent type detection uses regex patterns and alias normalization to categorize cases as invention, utility_model, or design.
- Type-specific validation enforces schema requirements: utility models need structure schemas and lineart, while design patents require appearance schemas plus photo assets.
- Exit code 2 signals missing materials, preventing incomplete cases from proceeding to downstream processing.
Frequently Asked Questions
How does the script handle multiple disclosure files in one case directory?
The find_disclosure function employs a scoring mechanism that prefers files matching timestamp patterns (e.g., 交底书_20240101120000.md) or containing the "技术交底书" header. If multiple candidates exist, it selects the most recently modified file that matches these criteria, ensuring deterministic selection without manual intervention.
Can I override the patent type detection if the disclosure document is ambiguous?
Yes. The script accepts a --type command-line argument that bypasses automatic detection. When provided, the value is validated against TYPE_ALIASES and used directly in the check_case function, skipping the detect_type_from_disclosure logic entirely. This is useful for testing or when processing legacy documents with non-standard headers.
What happens if the figure plan references assets that don't exist on disk?
The validation logic in check_case (lines 136‑225) verifies that referenced lineart and photo entries in the figure plan correspond to actual files in the case directory. If assets are referenced but missing, they are added to the missing list in the result dictionary, causing the script to exit with code 2 and report the specific gaps in the APPLICATION_GATE output line.
Why does the invention patent type require fewer validation checks than utility models or designs?
According to the source code implementation, invention patents (发明) are considered sufficiently documented by the disclosure text alone, which must contain detailed claims and technical descriptions. In contrast, utility models and design patents require additional structural or appearance schemas plus corresponding visual assets (lineart/photos) to satisfy patent office filing requirements, necessitating stricter material validation.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →