Fluxon version 0.0.3"
Pronunciation: Fluhk-sawn
Fluxon is a Python library designed for crafting structured prompts and parsing structured outputs, with a primary focus on JSON. Fluxon bridges the gap between human-readable prompts and machine-readable structured data, enabling seamless interaction with large language models (LLMs). It ensures robust error recovery, validation, and the generation of well-structured prompts tailored to LLMs.
Features
- Prompt Formatting: Guides LLMs to generate structured outputs using schemas and custom tags.
- Schema-Driven Parsing: Validates and parses outputs with tools like YAML, JSON Schema, or Pydantic classes.
- Error-Tolerant Parsing: Repairs common JSON issues such as missing commas, invalid formatting, and unquoted keys.
- Comprehensive Validation: Ensures outputs conform to expected structures using schema validation.
- Preprocessing Tools: Cleans LLM-generated outputs by removing comments and isolating JSON content.
- Lightweight and Modular Design: Optimized for Python-based workflows.
Installation
To install Fluxon, use pip:
pip install fluxon
Usage
1. Prompt Formatting
Create structured prompts to guide LLMs:
from fluxon.prompter import format_prompt
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer"}
},
"required": ["name", "age"]
}
prompt = "Provide user details in JSON format."
formatted_prompt = format_prompt(prompt, schema)
print("Prompt to LLM:", formatted_prompt)
Output:
Provide user details in JSON format.
Output the JSON object between the tags:
BEGIN_JSON
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
}
},
"required": [
"name",
"age"
]
}
END_JSON
2. Parsing and Error Recovery
Use Fluxon to clean and parse LLM outputs:
from fluxon.parser import clean_llm_output, parse_json_with_recovery
llm_output = """
BEGIN_JSON
{
"name": "Alice",
"age": 25
"city": "New York"
}
END_JSON
"""
# Step 1: Clean the LLM output
cleaned_output = clean_llm_output(llm_output)
# Step 2: Parse and recover JSON
parsed_json = parse_json_with_recovery(cleaned_output)
print("Parsed JSON:", parsed_json)
Output:
{
"name": "Alice",
"age": 25,
"city": "New York"
}
3. Validation and Repair
Validate or repair JSON outputs using schemas:
from fluxon.validator import validate_with_schema, repair_with_schema
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "integer", "default": 30}
},
"required": ["name", "age"]
}
json_obj = {"name": "Alice"}
# Validate the JSON object
is_valid = validate_with_schema(json_obj, schema)
print("Is valid:", is_valid)
# Repair the JSON object by filling defaults
repaired_json = repair_with_schema(json_obj, schema)
print("Repaired JSON:", repaired_json)
Output:
Is valid: False
Repaired JSON: {"name": "Alice", "age": 30}
Contributing
Contributions are welcome! Please submit pull requests or report issues on the GitHub repository.
License
Fluxon is licensed under the Apache License 2.0.
Start building error-resilient, structured workflows with Fluxon today!
Release files for fluxon 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fluxon-0.0.3.tar.gz | 13.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fluxon-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.3 kB
Release files / fluxon-0.0.3.tar.gz
| Download URL | fluxon-0.0.3.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e55492a2ed2c528e1b4dee9fc614f047b5b841f5382a7d0ee731ee1a27ee75fd
|
|
BLAKE2b-256 checksum How to use checksums |
1ac1cf67651dbcb15e8684a83057eec1451e2a3bd8903b4b4866c40ad68768f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.11
|
Release files / fluxon-0.0.3-py3-none-any.whl
| Download URL | fluxon-0.0.3-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8863efb3a541e7d024e522f19d0dbdee8ef0517857005709302b27dfe7b6d035
|
|
BLAKE2b-256 checksum How to use checksums |
34105271e3500d290c1e4cbce2290b8bbf2c17dedc82b715afe896fbe8fa2fb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.11.11
|