Standalone defect-checking engine for AI Skills, Tools, and Prompts
pip install defect-check==1.2.14 Copy PIP instructions
defect-check is a standalone, framework-free inspection engine for AI artifacts, built by SanityOps. It accepts Skills, Tools, and Prompts as input, runs multi-dimensional quality checks, and returns structured defect reports with scores and severity ratings.
pip install defect-check Requires Python ≥ 3.11
Runnable versions of these snippets (plus a custom-YAML example) live in examples/.
import asyncio import defect_check async def main(): result = await defect_check.check( tools=[ { "name": "lookup_order", "description": "Query orders by order ID", "parameters": {"type": "object"}, } ], prompts=[ {"name": "system", "content": "You are an order assistant."} ], skills=[ {"id": "orders", "name": "orders", "content": "# Orders workflow"} ], llm_provider="openai", llm_base_url="https://api.example.com/v1", llm_api_key="your-api-key", llm_model_id="your-model-id", ) print(result) asyncio.run(main()) Recommended: the DefectChecker class For repeated use, create a DefectChecker once with your LLM settings and reuse it — no need to pass base parameters on every call. All check methods are async.
import asyncio from defect_check import DefectChecker async def main(): # Configure everything up front (max_retries defaults to 3, max_concurrency to 5) checker = DefectChecker( llm_provider="openai", llm_base_url="https://api.example.com/v1", llm_api_key="your-api-key", llm_model_id="your-model-id", max_retries=3, # retries for recoverable LLM errors max_concurrency=5, # max in-flight LLM requests across all calls ) result = await checker.defect_check( tools=[{"name": "lookup_order", "description": "Query orders by order ID"}], prompts=[{"name": "system", "content": "You are an order assistant."}], skills=[{"id": "orders", "name": "orders", "content": "# Orders workflow"}], ) single = await checker.check_single(tool={"name": "lookup_order"}) cross = await checker.cross_defect_check(prompt="You are...", skills=skills, tools=tools) await checker.close() asyncio.run(main()) You can also create the checker first and configure it later via setter methods:
checker = DefectChecker() checker.set_llm_config(llm_provider="openai", llm_api_key="sk-...", llm_model_id="gpt-4o") checker.set_max_retries(5) # override the default of 3 checker.set_max_concurrency(10) # override the default of 5 result = await checker.defect_check(tools=tools) Inspection Levels Use check_level to control inspection depth:
result = await defect_check.check( tools=tools, prompts=prompts, skills=skills, check_level="L3", llm_provider="openai", llm_api_key="your-api-key", llm_model_id="your-model-id", ) When omitted, QDS determines the level using the bundled checklist, while QDT, QDP, and Cross determine it via the LLM. You can also pass check_level through options:
Two additional options in DefectCheckOptions control the QD-PM permission inspection:
Invalid or_level values (anything other than OR-L1/OR-L2/OR-L3/None) raise a ValueError.
LLM settings are passed explicitly by the caller — the public check API does not read .env files or environment variables for LLM configuration.
You can also pass a pre-configured client object via the provider parameter, bypassing the four llm_* parameters:
from defect_check.llm import DefectCheckTextClient # Build your own client, then pass it in client = DefectCheckTextClient(my_custom_provider) result = await defect_check.check( tools=tools, prompts=prompts, skills=skills, provider=client, ) The same llm_* / provider parameters are accepted by DefectChecker(...) and checker.set_llm_config(...).
The LLM client applies two protections that you can tune (defaults shown):
checker = DefectChecker(provider=my_client, max_retries=5, max_concurrency=10) Best practice: set max_concurrency before running your first check. Changing it afterwards rebuilds the underlying client's shared semaphore, which briefly releases coordination for in-flight callers.
If the LLM configuration is missing when a check runs, the response carries an LLM_CONFIGURATION_MISSING error instead of raising an exception.
You can override the built-in inspection rules and prompt templates with custom YAML files:
checker = DefectChecker( llm_provider="openai", llm_api_key="your-api-key", llm_model_id="gpt-4o", yaml_overrides={ "qds_scoring": "/path/to/custom_qds_rules.yaml", "prompt_qds": "/path/to/custom_qds_prompt.yaml", }, ) # Or switch at runtime checker.set_yaml_overrides({"qds_scoring": "/another/config.yaml"}) # Reset to built-in defaults checker.set_yaml_overrides(None) Supported override keys:
For detailed YAML schema, domain-specific extensions, and examples, see Custom YAML Configuration.
The package provides five inspection modules, each targeting a different artifact dimension:
Every supplied Skill, Tool, and Prompt is inspected. The response always uses a consistent envelope — results is always a list: one input produces one result item, multiple inputs produce multiple result items.
Inspection rules and prompt templates are packaged in the wheel. QDT, QDP, and Cross load YAML resources; QDS loads the bundled checklist.py.
QD-PM is a safety-focused module that inspects permission and operation risks in AI artifacts. It runs after single-artifact and cross-artifact inspections, subject to Gate-0 pre-validation.
Before QD-PM runs, Gate-0 validates four structural preconditions:
If any precondition fails, QD-PM returns an "evaluation cannot be performed" signal instead of a defect list.
LevelDeterminer → EntryGate → ViewGenerator → Checklist → CheckExecutor → Enricher → Scorer → Adapter Stage Responsibility LevelDeterminer Determine check level (L1/L2/L3) from artifact content — keyword-based (QDS) or LLM-based (QDP/QDT) EntryGate Deterministic pre-check — QDS-0 gate validates frontmatter before scoring ViewGenerator Optional intermediate view (QDS) Checklist Derive the applicable check list from the domain defect registry CheckExecutor Main inspection logic — the per-domain executor (QDPExecutor, QDS GroupedParallelExecutor, QDTExecutor) Enricher Fill missing defect metadata from the registry Scorer Compute score, grade, and gate result via the unified UnifiedScorer Adapter Convert internal findings to the public DefectItem contract All three domains feed the same InspectionPipeline (see defect_check/orchestrator.py), which is what the public check / check_single entry points call. This guarantees identical contract behavior across domains while keeping QDS-specific features (QDS-0 gate, intermediate view, grouped parallel execution) as first-class framework concepts.
The orchestrator also runs QD-PM (Permission Inspection) after the single-artifact and cross-artifact stages, gated by Gate-0 pre-validation. QD-PM inspects permission proportionality using operation risk levels (OR-L) and agent capability levels (AC-L).
To add a new domain, implement a DomainRegistration (level determiner, gate, view generator, executor, enricher, scorer) and register it in DomainRegistry — see docs/architecture.md for details.
{ "schema_version": "1.0", "status": "completed", "results": [ { "module": "QDT", "check_type": "artifact", "status": "completed", "check_level": "L2", "artifacts": [{"type": "tool", "id": "lookup_order", "name": "lookup_order"}], "score": {"total_score": 100.0, "max_score": 100.0, "grade": null, "gate_result": "PASS"}, "defect_summary": {"total_defects": 0, "p0_count": 0, "p1_count": 0, "p2_count": 0}, "defects": [], "error": null, "details": {}, "metadata": {} } ], "summary": { "total_results": 1, "completed_results": 1, "failed_results": 0, "skipped_results": 0, "total_defects": 0, "p0_count": 0, "p1_count": 0, "p2_count": 0, "gate_result": "PASS" }, "errors": [], "metadata": {"execution_time_seconds": 0.0} } Defect Fields Each defect in the defects list contains these canonical fields:
Inspect caller-provided Skills, Tools, and Prompts.
async def check( tools: list[dict] | None, prompts: list[dict] | None, skills: list[dict] | None, *, check_level: str | None = None, options: DefectCheckOptions | dict | None = None, provider: Any | None = None, llm_provider: str | None = None, llm_base_url: str | None = None, llm_api_key: str | None = None, llm_model_id: str | None = None, ) -> dict[str, Any] defect_check.check_single(...) Inspect a single artifact — exactly one of tool, prompt, or skill (or a combination; each is wrapped into a one-element list internally):
async def check_single( *, tool: Any | None = None, prompt: Any | None = None, skill: Any | None = None, check_level: str | None = None, options: DefectCheckOptions | dict | None = None, provider: Any | None = None, llm_provider: str | None = None, llm_base_url: str | None = None, llm_api_key: str | None = None, llm_model_id: str | None = None, ) -> dict[str, Any] defect_check.check_cross(...) Run only the cross-artifact inspection (PS/PT/ST) over caller-provided artifacts — no single-artifact stages, no QD-PM:
async def check_cross( *, prompt: str | None, skills: list[Any] | None, tools: list[Any] | None, check_level: str | None = None, provider: Any | None = None, llm_provider: str | None = None, llm_base_url: str | None = None, llm_api_key: str | None = None, llm_model_id: str | None = None, ) -> dict[str, Any] DefectChecker class A stateful facade that holds LLM configuration, retry, and concurrency settings — configure once, then run checks as instance methods.
from defect_check import DefectChecker checker = DefectChecker( provider: Any | None = None, # pre-configured client/provider (optional) llm_provider: str | None = None, llm_base_url: str | None = None, llm_api_key: str | None = None, llm_model_id: str | None = None, max_retries: int = 3, max_concurrency: int = 5, options: DefectCheckOptions | dict | None = None, # instance-level defaults yaml_overrides: dict[str, str] | None = None, # custom YAML config overrides ) # Configuration setters (can be called after construction) checker.set_llm_config(llm_provider=..., llm_api_key=..., llm_model_id=...) checker.set_max_retries(5) checker.set_max_concurrency(10) checker.set_options({"check_level": "L2"}) checker.set_yaml_overrides({"qds_scoring": "/path/to/custom.yaml"}) # custom rules # Inspection methods (all async; parameter signatures match the module-level functions) await checker.defect_check(tools=..., prompts=..., skills=...) # full inspection await checker.check_single(tool=..., prompt=..., skill=...) # single artifact await checker.cross_defect_check(prompt=..., skills=..., tools=...) # PS/PT/ST only await checker.close() # release the LLM connection Precedence for check settings: explicit method arguments > instance configuration (set_options / constructor options) > built-in defaults. Call-level check_level overrides the instance level without conflict errors.
Contributions are welcome! See CONTRIBUTING.md for development setup, testing conventions, and the PR workflow — the short version: fork, create a feature branch, write a failing test first, keep the public API stable, and open a Pull Request.
The engine is also available as a hosted SaaS service at demo.sanityops.org — no installation required.
Questions or feedback about the open-source engine or SanityOps? Contact hello@sanityops.org.
This project is licensed under the Apache License 2.0 — see the LICENSE file for details.
defect-check qa quality-assurance llm ai skills tools prompts inspection static-analysis
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 15, 2026.




