Learning resourcesReviewed · Pydantic

Pydantic AI Harness Artifact Scanning

This guide helps Python agent developers check saved memory and skills for suspicious instructions, but its pattern matching can miss attacks and flag harmless text. It explains Pydantic AI Harness’s ArtifactScanner, its Memory and Skills integrations, custom detection rules and tracing behavior.

Researched 24 Nov 2026

In short.

This guide shows Python agent developers how to screen persistent memory and skills for attack patterns, but a clean result does not establish safety. It documents automatic rejection or withholding through Memory and Skills, direct text scanning, configurable rules and trace events. Protection depends on routing content through the scanner; other file-access paths can bypass it. Detection accuracy, performance, costs and compatibility with a specific release are not established.

Researched and written by an AI model and checked by a second AI model. How it works

Covers the complete selected page at [https://pydantic.dev/docs/ai/harness/artifact-scanning/index.md], including its API reference, limitations, 0.x version notice, documentation-index notice and request-query notices. Linked implementation files, installation guidance, Memory and Skills documentation, version policy, Prompt Injection Defender and Guardrails pages are excluded. No code was executed; integration behavior, example outputs, detection accuracy and performance remain untested. No implementation package or licence evidence is supplied.

The overview

Identity

This is the artifact-scanning guide and API reference for Pydantic AI Harness at [https://pydantic.dev/docs/ai/harness/artifact-scanning/index.md]. It describes ArtifactScanner, a Python component for inspecting text that an agent saves and a later session may load.

The central use case is persistent content, such as memory files and reusable skills, where a planted instruction could influence a future session.

Assessment

The documented interfaces suggest a useful additional check for applications that control how agents store and load persistent text. The guide explains both the blocking behavior and the paths that escape scanning, which helps developers assess whether the integration covers their application.

Its practical value depends on coverage and tolerance for false alarms. The page supplies no measurements establishing how reliably the patterns distinguish malicious instructions from ordinary content.

Users

The guide is for Python developers building agents that retain memory or load skills written by models or third parties. Beginners get integration examples; experienced developers get configuration details, result types, extension points and tracing semantics.

Applications that store quoted attacks, security notes or skills containing HTML comments may need category tuning because legitimate material can match the built-in rules.

Capabilities

ArtifactScanner looks for instruction overrides, role changes, credential-exfiltration patterns, HTML comments and specified invisible Unicode characters. Through Memory and Skills, a flagged memory write is refused, flagged memory content is withheld and a flagged skill is omitted from the catalog.

Direct scan calls return findings and a flagged boolean. Each finding contains a threat category, pattern name and excerpt of at most 80 characters, with invisible characters represented by code points. The summary() method returns threat and pattern names without quoting artifact content.

Capability decisions on flagged artifacts create zero-duration artifact_scan flagged trace spans with the action, threats, patterns and finding count. Source labels and excerpts appear only when trace_include_content is enabled. Clean scans and direct scan calls do not emit these spans.

Using it

Requirements

Using the documented API requires Python code with pydantic_ai_harness available. The integration example also imports Agent from pydantic_ai and LocalWorkspace from pydantic_ai.capabilities.

The page does not specify installation commands, supported Python versions, operating-system requirements or compatible package versions. A replacement detector must fit the synchronous scan(content, *, source=...) interface and return a result exposing flagged.

Mechanism

The built-in detector matches text patterns without I/O. Before phrase matching, it applies NFKC Unicode normalization and removes default-ignorable characters, preventing full-width letters or hidden characters inside a phrase from concealing a match.

Unicode checks distinguish listed suspicious formatting characters from permitted uses, including joiners used in scripts and emoji, directional marks and certain variation selectors.

The threats option selects built-in categories, all enabled by default. extra_patterns adds named regular expressions under the custom category and matches them case-insensitively against normalized text. Unknown categories, reused built-in pattern names, invalid expressions and configurations with nothing to scan raise UserError during construction.

Setup

The documented setup creates ArtifactScanner() and passes the instance as scanner= to Memory and Skills. Its Agent example combines LocalWorkspace('.'), Memory(scanner=scanner) and Skills('.agents/skills', scanner=scanner).

For other artifacts, call scan before storage or prompt loading and inspect result.flagged. A direct call only returns findings; the application must implement its own refusal, withholding or review behavior.

Example

The guide illustrates scanning a notes.md sentence that combines an instruction override with a request to read an SSH private key. Its shown result is flagged, with summary entries exfiltration (read_credential_file) and injection (ignore_instructions). These are documentation examples, not independently measured results.

A separate example adds an internal_host regex and matches text containing build.corp.internal. This demonstrates how an application can add a content rule beyond the built-in categories.

Assessment & evidence

Limitations

Pattern matching can miss paraphrased or translated instructions and can flag harmless quotations of attacks. An empty findings collection does not establish that content is safe.

Automatic coverage includes memory text passing through write_memory, read_memory, search_memory and injected MEMORY.md, plus each skill’s description, when_to_use and body. Bundled skill files are scanned when read through Skills(read_files=True). Memory accessed through FileSystem, skill files read through other routes and other artifacts require explicit scanning.

Custom patterns operate on normalized text, so patterns containing characters removed during normalization cannot match as written. The page supplies no detection benchmarks, multilingual evaluation or evidence of protection across every file-access path.

Reasoning

The design addresses a specific persistence risk: instructions written during one session can become input to another. Refusing a memory write and withholding suspicious content at loading provide intervention points on both sides of that boundary.

The coverage limits imply that adoption should include mapping actual file-access paths. A scanner attached to Memory and Skills cannot cover reads that bypass those integrations. Broader category selection also creates a tradeoff between catching more suspicious text and rejecting legitimate material.

Alternatives

For a different detector behind the same artifact interface, the guide supports subclassing ArtifactScanner and overriding scan, including with a classifier or service. It provides no comparative effectiveness or cost evidence.

The page points to Prompt Injection Defender for instructions arriving through tool results [https://pydantic.dev/docs/ai/harness/prompt-injection-defender/] and Guardrails for secrets and personal data in prompts and outputs [https://pydantic.dev/docs/ai/harness/guardrails/]. Those linked pages are outside the available evidence, so their implementation and effectiveness are unassessed.

Evidence

The evidence consists of the complete artifact-scanning documentation page, including usage examples, detection categories, configuration, telemetry, limitations and API definitions. Its captured source revision is sha256:2e3910585e66267c4d2a0187b5b88be52adcb7e0b54918228456282293fb223b.

The linked implementation and related documentation are not included. The described outputs and behavior are documentation claims, not execution results. Detection accuracy, runtime performance and working compatibility with a particular release remain unassessed.

Access & freshness

Costs

Cost is unknown. The page provides no pricing, licence fees or operating-cost estimates.

Although built-in scanning is described as synchronous pattern matching without I/O, CPU usage, memory consumption, throughput and latency are not measured. Costs associated with a replacement classifier or external service are also unknown.

Rights

The page links to implementation source at [https://github.com/pydantic/pydantic-ai/tree/main/src/pydantic_ai_harness/pydantic_ai_harness/artifact_scanning/], but contains no licence text or redistribution terms.

Permissions for copying the documentation or using, modifying and redistributing the implementation are not established by this page.

Freshness

The documentation snapshot was captured on 2026-11-24 at 01:24:41.326 UTC. The page does not identify an exact package release or its own publication or update date.

Its version notice says Pydantic AI Harness is on 0.x releases and APIs may change between minor releases, with deprecation warnings and migration guidance in release notes. Compatibility with a particular installed version is unknown.

Actions

Before adopting the API, confirm installation requirements and compatibility for the intended Harness version. Map memory and skill access paths, attach the scanner to supported integrations and add explicit checks wherever content bypasses them.

Evaluate representative benign text, quoted attacks, multilingual instructions and unusual Unicode before choosing categories and custom patterns. Define how flagged content will be handled, and review trace_include_content because enabling it can place source labels and matched excerpts in traces.

Evidence for this report

selected-page.txtselected · checked 2026-11-24