Skip to main content

Context Compiler Directive Drafter

Directive Drafter helps turn a user's words into a possible Context Compiler directive. It starts with predictable rules. You can add an optional fallback for requests those rules cannot understand with confidence.

The Drafter only makes suggestions. Context Compiler makes the final decision and is the only component that applies a directive or changes saved state.

Installation

pip install "context-compiler-directive-drafter"

For development:

uv sync --group dev

Basic usage

This example uses the built-in rules. It turns I prefer concise replies into use concise replies:

from context_compiler import Engine
from context_compiler.grammar import CanonicalDirective

from context_compiler_directive_drafter import (
    DirectiveDrafter,
    RejectedDirective,
    UnknownDirective,
)

drafter = DirectiveDrafter()
engine = Engine()
draft_result = drafter.draft_directive("I prefer concise replies")

if isinstance(draft_result.result, CanonicalDirective):
    print("Candidate directive:", draft_result.result.text)  # use concise replies
    if input("Confirm and apply this directive? [y/N] ").lower() == "y":
        decision = engine.apply_directive(draft_result.result)
        print("Compiler decision:", decision)
elif isinstance(draft_result.result, RejectedDirective):
    print("Directive acquisition rejected:", draft_result.result.reason)
elif isinstance(draft_result.result, UnknownDirective):
    print("Need clarification or optional fallback:", draft_result.result.reason)

DraftResult.result can be one of three things:

  • CanonicalDirective: a possible directive for the host to review;
  • RejectedDirective: drafting ended with a terminal rejection and no candidate directive;
  • UnknownDirective: the input is unclear and may be sent to an optional fallback.

The source field says where the result came from. It does not mean that the compiler approved the result or applied it.

Optional fallbacks

Directive Drafter has two acquisition paths. The built-in heuristic path uses deterministic, bounded recognition and rewrite rules. An optional semantic fallback handles eligible inputs that the heuristic path leaves unresolved. A semantic fallback may use a model or another implementation, and is not needed for basic Directive Drafter use.

Fallbacks are optional helpers for UnknownDirective results. They receive the original input and may suggest directive text for the host to review. For example, a fallback may interpret:

The intended audience is senior management

as:

set premise intended audience is senior management

The premise example needs a fallback; the built-in rules do not interpret it on their own. Available fallback integrations depend on the implementation. See the Python fallback integrations document for provider-specific setup.

Authority boundary

The host decides whether to accept a proposed CanonicalDirective. After the user confirms it, the host can pass it to Context Compiler with engine.apply_directive(...). Drafter-produced CanonicalDirective candidates are the reviewed handoff for this workflow. The Drafter must not read or change compiler state.

Further documentation

Development

uv run pre-commit run --all-files
uv run pytest

License

Apache-2.0

Metadata

Release files for context-compiler-directive-drafter 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for context-compiler-directive-drafter 0.2.0
File Size Uploaded
context_compiler_directive_drafter-0.2.0.tar.gz 278.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for context-compiler-directive-drafter 0.2.0
File Interpreter ABI Platform
context_compiler_directive_drafter-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 307.9 kB

Release files / context_compiler_directive_drafter-0.2.0.tar.gz

Download URL context_compiler_directive_drafter-0.2.0.tar.gz
Size 278.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4826794ae9370956a980c1083cee681e3e6d1e3d18108150bc12e539b574c190
BLAKE2b-256 checksum
How to use checksums
8921c08999361a17084ed9c1744a69c95aded63433d338e01fbca92a0d11ed11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

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 Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log

Release files / context_compiler_directive_drafter-0.2.0-py3-none-any.whl

Download URL context_compiler_directive_drafter-0.2.0-py3-none-any.whl
Size 29.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d86fc60ab22c6ec6b7126e369ad5ae5249338d3c863b15428e06f81c1b472df
BLAKE2b-256 checksum
How to use checksums
891c09f7033426070196ae2771290c40b7cbc26235cd4b3cb26343d535f27ccc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

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 Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 20, 2026.

Transparency log
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page