Skip to content

Commit fc92f27

Browse files
anticomputerCopilot
andcommitted
Avoid duplicated outputs-schema error prefix and double personality load
Surface the OutputSchemaError message directly instead of re-adding the "invalid 'outputs' schema:" prefix it already carries, which produced duplicated text for malformed schemas. Load each agent personality once in the linter and reuse it for its toolbox checks, reporting the same missing-personality error on failure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8cf8b61 commit fc92f27

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

src/seclab_taskflow_agent/linting.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,16 @@ def _lint_task(task: TaskDefinition, location: str, ctx: _Ctx) -> None:
140140

141141
# Agents (personalities) and their toolboxes.
142142
for agent_name in task.agents or []:
143-
if _check_reference(at.get_personality, agent_name, "personality", location, ctx):
143+
try:
144144
personality = at.get_personality(agent_name)
145-
if not (task.toolboxes or []):
146-
for tb in personality.toolboxes or []:
147-
_check_reference(at.get_toolbox, tb, "toolbox", location, ctx)
145+
except Exception as exc: # noqa: BLE001 - loader raises several types
146+
ctx.add(
147+
"error", "missing-personality", f"cannot load personality {agent_name!r}: {exc}", location
148+
)
149+
continue
150+
if not (task.toolboxes or []):
151+
for tb in personality.toolboxes or []:
152+
_check_reference(at.get_toolbox, tb, "toolbox", location, ctx)
148153

149154
# Task-level toolbox overrides.
150155
for tb in task.toolboxes or []:

src/seclab_taskflow_agent/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ def _validate_outputs(self) -> TaskDefinition:
222222
try:
223223
validate_output_schema(self.outputs)
224224
except OutputSchemaError as exc:
225-
raise ValueError(f"invalid 'outputs' schema: {exc}") from exc
225+
# OutputSchemaError already carries a fully-formed, descriptive
226+
# message; surface it directly rather than re-prefixing (which
227+
# would duplicate its "invalid 'outputs' schema:" prefix).
228+
raise ValueError(str(exc)) from exc
226229
if self.over and not self.repeat_prompt:
227230
raise ValueError("'over' only applies to repeat_prompt tasks")
228231
return self

tests/test_models.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ def test_invalid_outputs_schema_rejected_at_load(self):
224224
with pytest.raises(ValidationError, match="invalid 'outputs' schema"):
225225
TaskDefinition(id="x", user_prompt="hi", outputs={"type": "not-a-json-schema-type"})
226226

227+
def test_invalid_outputs_schema_message_not_double_prefixed(self):
228+
with pytest.raises(ValidationError) as exc_info:
229+
TaskDefinition(id="x", user_prompt="hi", outputs={"type": "not-a-json-schema-type"})
230+
assert str(exc_info.value).count("invalid 'outputs' schema:") == 1
231+
227232
def test_over_requires_repeat_prompt(self):
228233
with pytest.raises(ValidationError, match="'over' only applies to repeat_prompt"):
229234
TaskDefinition(user_prompt="{{ result }}", over="outputs.x.items")

0 commit comments

Comments
 (0)