ChainWeaver python-source.instructions.md

Python coding rules for the ChainWeaver production source folder. They cover module documentation, Pydantic data models, custom errors, and export conventions.

In plain words
What is it for?
Use them when adding or changing ChainWeaver modules, data schemas, public classes and functions, error handling, or package exports.
Why use it?
They keep Python code consistent and avoid outdated Pydantic patterns or incorrectly defined exceptions.

Instructions file for GitHub Copilot

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add instructions/dgenio/chainweaver/python-source
Clone the repo
git clone --depth 1 https://github.com/dgenio/ChainWeaver

Made for: GitHub Copilot.

Per session 386 This file is loaded in full into every session.
When invoked 386 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00386 $0.00386
Opus 5 $0.00193 $0.00193
Sonnet 5 $0.00077 $0.00077
Haiku 4.5 $0.00039 $0.00039

Measured yesterday against content hash 04fc7346e3f4, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

ChainWeaver python-source.instructions.md scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.github/instructions/python-source.instructions.md · 36 lines

What it actually says

Python source instructions — ChainWeaver

These instructions apply when editing production source code in chainweaver/.

Module conventions

  • Every module has a module-level docstring explaining its role
  • Include from __future__ import annotations immediately after the module docstring
  • All public classes and functions have Google-style docstrings

Pydantic patterns

  • Use pydantic.BaseModel for schemas / I/O contracts (v2 API)
  • For BaseModel types, use model_dump() not .dict() (v2 migration)
  • For BaseModel types, use model_validate() not .parse_obj() (v2 migration)
  • Field descriptions via Field(description="...") for schema clarity
  • Internal runtime records that need to carry Exception instances may remain dataclasses per repo invariants

Exception patterns

  • All custom exceptions inherit from ChainWeaverError
  • Exceptions should carry relevant context attributes where applicable; do not assume a uniform constructor signature — follow the API defined by each exception class in chainweaver.exceptions
  • Import exceptions from chainweaver.exceptions, never define inline
  • Available exception types: ToolNotFoundError, FlowNotFoundError, FlowAlreadyExistsError, SchemaValidationError, InputMappingError, FlowExecutionError, ToolDefinitionError

Export rules

  • Any new public class/function MUST be added to chainweaver/__init__.py __all__
  • If adding a new module, add its imports to __init__.py

Executor invariant

  • executor.py must remain deterministic: no LLM calls, no network I/O, no randomness
  • The executor runs a compiled graph — it does not make decisions
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 36 lines · 386 tokens per session scan A 04fc7346e3f4

Subscribe to this mod's changes

ChainWeaver python-source.instructions.md is an instructions file published in the GitHub repository dgenio/ChainWeaver (6 stars, last pushed 2d ago), licensed Apache-2.0. It adds 386 tokens to every session, about $0.0019 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.