findings_io
strands_teams.findings_io ¶
Serialize and parse typed Finding collections to/from findings.json.
The write path (write_findings) and the read path (read_team_findings) share these helpers so the on-disk shape has exactly one producer and one consumer. Both validate through pydantic over parsed JSON at the parse boundary (AC-8-4): a findings.json is a JSON array of finding objects, each validated by :class:~strands_teams.models.Finding. Unknown keys or out-of-range values are rejected (FrozenModel is extra="forbid") rather than silently coerced, so malformed on-disk content is caught here, not downstream.
None of these helpers raise across the tool boundary for expected failures — :func:parse_findings raises pydantic.ValidationError / ValueError which the callers catch and turn into a {"status": "error", ...} result or a markdown fallback.
serialize_findings ¶
Serialize a list of Finding objects to a JSON-array string.
Uses the model's model_dump_json-equivalent form via a TypeAdapter so datetimes and nested Evidence models round-trip through pydantic (AC-3-2, AC-8-1).
Source code in packages/strands-teams/src/strands_teams/findings_io.py
parse_findings ¶
Parse and validate a findings.json payload into typed Finding objects.
Validates JSON text (not an arbitrary Python object) so malformed on-disk content is caught at the parse boundary (AC-8-4).
Raises:
| Type | Description |
|---|---|
ValidationError | If the payload is not a JSON array of valid |
Source code in packages/strands-teams/src/strands_teams/findings_io.py
coerce_findings ¶
Validate an already-parsed Python object (e.g. a list of dicts) into findings.
Used by the write path, whose input arrives as tool arguments (dicts), not as a JSON string. Still routes through the same adapter so the schema is enforced identically (AC-3-4).
Raises:
| Type | Description |
|---|---|
ValidationError | If any element is not a valid |
Source code in packages/strands-teams/src/strands_teams/findings_io.py
load_findings ¶
Read and validate the typed findings at path.
Raises:
| Type | Description |
|---|---|
OSError | If the file cannot be read. |
ValidationError | JSONDecodeError | If the content is not a valid findings array. |
Source code in packages/strands-teams/src/strands_teams/findings_io.py
findings_as_dicts ¶
Return findings as JSON-mode dicts for embedding in a tool's JSON result.
mode="json" renders datetimes as ISO strings so the surrounding json.dumps in the tool result does not choke on datetime objects.