
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Proxy Structuring Engine: Stateful AI-generated output with a focus on creativity, speed, and structure.
Eliminate 100% of schema violations and state tracking failures in your LLM applications.
Raw LLM outputs are structurally unpredictable, breaking systems that require specific formats (API calls, tool use, structured data). Prompting for structure is inconsistent; post-processing is inefficient and often fails on complex or nested formats.
The Proxy Structuring Engine (PSE) provides guaranteed structural validity by enforcing constraints during LLM generation.
Define your required output structure using Pydantic, JSON Schema, function signatures, or PSE's composable types. PSE compiles this into a high-performance Hierarchical State Machine (HSM). Integrated into the generation loop, the HSM engine guides the LLM, ensuring every generated token conforms to the defined structure.
Result: Structurally perfect output, generated correctly the first time.
pse.types
.process_logits
) and sampling (sample
) hooks. Optional mixins simplify transformers
integration (PyTorch, TF, JAX).pse.types
(Chain
, Loop
, Any
, etc.) to build custom HSMs for bespoke structural requirements beyond standard schemas.pip install pse
or
uv add pse
(Installs the pse
Python library and its required pse-core
dependency. See Installation Docs for framework extras and setup)
This example demonstrates generating JSON output matching a Pydantic schema using transformers
.
import torch
from transformers import AutoTokenizer, LlamaForCausalLM
from pydantic import BaseModel
from pse import StructuringEngine
from pse.util.torch_mixin import PSETorchMixin # Optional: Mixin for easy HF integration
# 1. Define structure
class UserProfile(BaseModel):
user_id: int
username: str
is_active: bool
roles: list[str]
# 2. (Optional) Apply PSE mixin to model class
class PSE_Llama(PSETorchMixin, LlamaForCausalLM): pass
# 3. Load model & tokenizer
model_path = "meta-llama/Llama-3.2-1B-Instruct" # Example
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = PSE_Llama.from_pretrained( # Or your base model class
model_path, torch_dtype=torch.bfloat16, device_map="auto"
)
if tokenizer.pad_token is None: tokenizer.pad_token = tokenizer.eos_token
model.config.pad_token_id = tokenizer.pad_token_id
# 4. Init & Configure Engine (Mixin attaches as model.engine)
model.engine = StructuringEngine(tokenizer)
model.engine.configure(UserProfile) # Compile structure to HSM
# 5. Create prompt & input IDs
prompt = f"Generate a user profile: ID 999, username 'tester', active true, roles ['qa', 'dev']. Output ONLY the JSON."
messages = [{"role": "user", "content": prompt}]
input_ids = tokenizer.apply_chat_template(
messages, return_tensors="pt", add_generation_prompt=True
).to(model.device)
# 6. Generate (PSE hooks applied via mixin or manually)
output_ids = model.generate(
input_ids, max_new_tokens=150, do_sample=True,
# Manual hook example (if not using mixin):
# logits_processor=[model.engine.process_logits], sampler=model.engine.sample
)
# 7. Decode & Parse (Guaranteed by PSE)
output_text = tokenizer.decode(output_ids[0][input_ids.shape[-1]:], skip_special_tokens=True)
structured_output: UserProfile | None = model.engine.get_structured_output(UserProfile)
print("Raw Output (Guided by PSE):\n", output_text)
print("\nParsed Pydantic Object:\n", structured_output)
# Expected: UserProfile(user_id=999, username='tester', is_active=True, roles=['qa', 'dev'])
See the examples/
directory for more use cases, including JSON Schema and custom StateMachine
composition.
PSE's runtime HSM enforcement offers fundamental advantages over other methods:
Capability | PSE (Runtime HSM) | Prompting / Retries | Regex / Post-Proc. | Simple Masking |
---|---|---|---|---|
Guaranteed Structure | 100% | Probabilistic | Fixes Errors | Flat Only |
Complex/Nested | Handles Natively | Brittle / Fails | Impractical | Cannot Handle |
Recursion | Handles Natively | No | No | No |
Reliability | Production Grade | Low | Error-prone | Brittle |
Efficiency | Optimized C++ | Retries Cost | Slow | Fast (Simple) |
Token Healing | Built-in | N/A | N/A | Breaks |
Integrate PSE into your generation loop via two hooks:
logits_processor=[engine.process_logits]
sampler=engine.sample
(wraps your base sampler)Works with PyTorch, TensorFlow, JAX, MLX, etc. Optional transformers
mixins simplify integration. (See Docs for details)
PSE provides the structural guarantees required for reliable agentic systems, powering the Proxy Base Agent (PBA) for dependable state transitions and tool use.
pse
(Python Library): Open source under Apache 2.0 (LICENSE). Provides the Python interface, schema parsing, and integration logic.pse-core
(C++ Engine): Required dependency. Distributed as a pre-compiled binary. Contains the high-performance HSM execution core. Source code is proprietary (The Proxy Company, Patent Pending).@software{Wind_Proxy_Structuring_Engine_2025,
author = {Wind, Jack},
title = {{Proxy Structuring Engine: Guaranteed Structured Output from Language Models via Runtime Hierarchical State Machine Enforcement}},
year = {2025}, # Adjust year if needed
publisher = {The Proxy Company},
version = {2025.06.1}, # Update version as needed
date = {2025-04-15}, # Update release date
url = {https://github.com/TheProxyCompany/proxy-structuring-engine}
}
FAQs
Proxy Structuring Engine: Stateful AI-generated output with a focus on creativity, speed, and structure.
We found that pse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.