midge-security 0.2.0
The Midge customer SDK. Prompts are authorized by Midge's fine-tuned Laya checkpoint; guards stop blocked code before execution.
from midge import Midge
# MIDGE_API_KEY is configured on your application server.
midge = Midge(base_url="http://127.0.0.1:8000")
verdict = midge.check("What is the capital of France?")
print(verdict.action, verdict.probabilities)
@midge.guard()
def tool(prompt: str):
return your_tool(prompt)
Keep API keys server-side. check, acheck, check_context, acheck_context, guard, and protect remain supported. Checks return a truthy ALLOW verdict or a falsy BLOCK verdict. Guards raise MidgeBlockedError on BLOCK; on_block can return a fallback without executing the protected function.
For this unpublished source version, install with pip install ./midge/midge-agent from the repository root. [local] installs the Laya runtime for Midge(offline=True); configure MIDGE_MODEL_PATH to the full fine-tuned checkpoint directory. [space] installs Gradio transport for Midge(space_id="OWNER/SPACE"); hf_token= is separate optional authentication for a private Space.
An explicit base_url= selects REST even when MIDGE_SPACE_ID is inherited from the environment. An explicit space_id= selects Space transport; supplying both arguments is a configuration error. Without either argument, MIDGE_SPACE_ID selects a Space, otherwise MIDGE_BASE_URL (or the legacy default) selects REST. Changing environment variables after importing the SDK does not update its import-time defaults: use explicit arguments or start a fresh process. offline=True explicitly selects local inference and is independent of backend availability. Remote clients never fall back to local inference.
To verify an outage, use the intended installed SDK, print midge.__file__ and midge.__version__, confirm client.offline is False, client.space_id is None, and an explicit local client.base_url. Stopping a local server says nothing about availability if the client actually targets a Space, another port, or the hosted default. Connection failures, timeouts, HTTP errors and invalid verdicts refuse guarded execution; raise_on_engine_error=True raises a connection exception instead. An on_block fallback can return normally without executing the protected body, so test a body execution counter rather than only checking whether a call returned.
The real-model regression script python scripts/smoke_guard_outage.py (from the repository root, in an environment with local model and backend dependencies) starts its own temporary localhost backend, verifies sync/async ALLOW and BLOCK plus authentication failure, stops that backend, confirms the exact port refuses connections, and verifies both guarded bodies stay unexecuted. It records SDK location, mode, endpoint and real verdicts in verification/guard_outage_smoke.json. It uses synthetic credentials, forbids external connections and never stops an independently running service.
0.2 compatibility changes: intent, risk level and threat score are None; the model does not produce them. Inspect label, probabilities, optional model-returned confidence/answer_confidence, usage, and error. The reason is a status string, not an inferred explanation. classification and legacy decision are unavailable. Legacy policy names are tags with the same model behavior; custom scoring policies are rejected. Alternate model overrides are rejected. OPENAI_API_KEY is no longer accepted as a customer key. Upgrade SDK and backend together: missing model output is refused, even if an older service says ALLOW.
Structured context preserves all item content, order, duplicates, kind, source and parent provenance as canonical JSON. Single-prompt source/provenance metadata, and session/correlation identifiers, are not shown to the model. Over-window inputs BLOCK; no context reduction occurs.
The CLI uses the same endpoint via Midge.check; its optional agent provider runs only after ALLOW. Legacy classifier, detector, context and provenance utilities remain importable for existing utility callers but are never consulted by SDK checks. Their historical tests do not establish model accuracy.
See the repository's docs/LAYA_MIGRATION.md for the response contract, exact context serialization, verification, local setup and manual HF demo deployment. This version has not been published to PyPI.
Metadata
Release files for midge-security 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| midge_security-0.2.0.tar.gz | 118.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| midge_security-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 207.3 kB
Release files / midge_security-0.2.0.tar.gz
| Download URL | midge_security-0.2.0.tar.gz |
|---|---|
| Size | 118.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
22a0923aeff11c3b9a073d08b1dfd7f89e29b559836524e105a732b55f5a2fae
|
|
BLAKE2b-256 checksum How to use checksums |
868e405ff63cb2293bb73e015d81e660dd4988b518d6aefb968b57ec273f4a62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / midge_security-0.2.0-py3-none-any.whl
| Download URL | midge_security-0.2.0-py3-none-any.whl |
|---|---|
| Size | 89.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38fbdf1f36d45d0f369e83a511df9dfc07d9457f64f0cdc475151b352c03c12b
|
|
BLAKE2b-256 checksum How to use checksums |
f2391aa1af8c1dd6c76f45a87e5f2efbd93091900a59422d12db6150d6002fb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for midge-security 0.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.