validate_file
Validate TwinCAT automation project files for code quality, structural integrity, and compliance with IEC 61131-3 standards to ensure safe compilation and import.
Instructions
Validate a single TwinCAT file.
Args: file_path: Path to TwinCAT file validation_level: "all", "critical", or "style" profile: Output profile - "full" (verbose, default) or "llm_strict" (minimal) intent_profile: Programming paradigm intent — "auto" (default), "procedural", or "oop". Controls which check families run: - "procedural": OOP checks are skipped. - "oop": Full OOP check family is enforced. - "auto": Resolved from file content (EXTENDS/IMPLEMENTS → oop, else procedural).
Returns: JSON string with validation results.
Full profile includes: validation_status, checks array, issues with Phase 3
enrichment, metrics, timing.
LLM strict profile includes only: file_path, safe_to_import, safe_to_compile,
blocking_count, blockers (unfixable errors).Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| validation_level | No | all | |
| profile | No | full | |
| enforcement_mode | No | strict | |
| intent_profile | No | auto |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The handler function 'validate_file' which validates a single TwinCAT file using the validation_engine.
def validate_file( file_path: str, validation_level: str = "all", profile: str = "full", enforcement_mode: str = DEFAULT_ENFORCEMENT_MODE, intent_profile: str = "auto", ) -> str: """Validate a single TwinCAT file. Args: file_path: Path to TwinCAT file validation_level: "all", "critical", or "style" profile: Output profile - "full" (verbose, default) or "llm_strict" (minimal) intent_profile: Programming paradigm intent — "auto" (default), "procedural", or "oop". Controls which check families run: - "procedural": OOP checks are skipped. - "oop": Full OOP check family is enforced. - "auto": Resolved from file content (EXTENDS/IMPLEMENTS → oop, else procedural). Returns: JSON string with validation results. Full profile includes: validation_status, checks array, issues with Phase 3 enrichment, metrics, timing. LLM strict profile includes only: file_path, safe_to_import, safe_to_compile, blocking_count, blockers (unfixable errors). """ _t0 = time.monotonic() ctx = None try: mode_error = _validate_enforcement_mode(enforcement_mode, start_time=_t0) if mode_error: return mode_error ctx = _resolve_execution_context(file_path, enforcement_mode=enforcement_mode) if intent_profile not in _VALID_INTENT_PROFILES: return _tool_error( f"Invalid intent_profile: {intent_profile}", file_path=file_path, start_time=_t0, execution_context=ctx, valid_intent_profiles=list(_VALID_INTENT_PROFILES), ) if validation_level not in ["all", "critical", "style"]: return _tool_error( f"Invalid validation_level: {validation_level}", file_path=file_path, start_time=_t0, execution_context=ctx, valid_levels=["all", "critical", "style"], ) profile_error = _validate_profile(profile, start_time=_t0, execution_context=ctx) if profile_error: return profile_error path, error = _validate_file_path(file_path, start_time=_t0, execution_context=ctx) if error: return error file = TwinCATFile.from_path(path) _intent_resolved = _resolve_intent_profile(file.content, intent_profile) _exclude_cats = frozenset({"oop"}) if _intent_resolved == "procedural" else None engine_start = time.time() engine_result = validation_engine.validate( file, validation_level, exclude_categories=_exclude_cats ) validation_time = time.time() - engine_start result = _convert_engine_result_to_mcp_format( engine_result, file, validation_time, validation_level, profile ) result["success"] = True return _with_meta(result, _t0, execution_context=ctx)