MCPcopy
hub / github.com/wshobson/agents / _check_nonempty_str_field

Function _check_nonempty_str_field

tools/validate_generated.py:67–108  ·  view source on GitHub ↗

Validate that `field` exists in `fm`, is a str, and is non-empty. Adds one Finding per violation. Returns True if the field passes all checks. ``label`` is only used in remediation hints (defaults to ``field``).

(
    report: Report,
    fm: dict,
    field: str,
    harness: str,
    path: Path,
    label: str = "",
)

Source from the content-addressed store, hash-verified

65
66
67def _check_nonempty_str_field(
68 report: Report,
69 fm: dict,
70 field: str,
71 harness: str,
72 path: Path,
73 label: str = "",
74) -> bool:
75 """Validate that `field` exists in `fm`, is a str, and is non-empty.
76
77 Adds one Finding per violation. Returns True if the field passes all checks.
78 ``label`` is only used in remediation hints (defaults to ``field``).
79 """
80 label = label or field
81 if field not in fm:
82 report.add(
83 severity="error",
84 harness=harness,
85 path=path,
86 message=f"missing required `{field}` field in frontmatter",
87 remediation=f"Each {harness} {label} needs a `{field}`.",
88 )
89 return False
90 if not isinstance(fm[field], str):
91 report.add(
92 severity="error",
93 harness=harness,
94 path=path,
95 message=f"`{field}` field must be a string",
96 remediation=f"Set `{field}` to a plain string in the {label} frontmatter.",
97 )
98 return False
99 if not fm[field].strip():
100 report.add(
101 severity="error",
102 harness=harness,
103 path=path,
104 message=f"`{field}` field is empty",
105 remediation=f"Provide a non-empty `{field}` in the {label} frontmatter.",
106 )
107 return False
108 return True
109
110
111# ── Codex validators ─────────────────────────────────────────────────────────

Callers 1

validate_copilotFunction · 0.85

Calls 1

addMethod · 0.45

Tested by

no test coverage detected