{"id":34039222,"url":"https://github.com/milistu/outformer","last_synced_at":"2026-04-09T04:31:44.015Z","repository":{"id":294041938,"uuid":"985827310","full_name":"milistu/outformer","owner":"milistu","description":"Clean Outputs from Language Models","archived":false,"fork":false,"pushed_at":"2025-06-10T07:07:05.000Z","size":2748,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-28T20:15:47.410Z","etag":null,"topics":["formatter","formatting","inference","json","llm","output","structure","structured-data","transformers"],"latest_commit_sha":null,"homepage":"https://outformer.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/milistu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-18T15:57:12.000Z","updated_at":"2025-09-16T15:39:55.000Z","dependencies_parsed_at":"2025-06-08T03:04:06.165Z","dependency_job_id":null,"html_url":"https://github.com/milistu/outformer","commit_stats":null,"previous_names":["milistu/outformer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/milistu/outformer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milistu%2Foutformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milistu%2Foutformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milistu%2Foutformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milistu%2Foutformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/milistu","download_url":"https://codeload.github.com/milistu/outformer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/milistu%2Foutformer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31586403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["formatter","formatting","inference","json","llm","output","structure","structured-data","transformers"],"created_at":"2025-12-13T21:29:52.040Z","updated_at":"2026-04-09T04:31:44.005Z","avatar_url":"https://github.com/milistu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!-- ![Outformer Logo](https://raw.githubusercontent.com/milistu/outformer/main/docs/img/logo_dark.png \"Outformer Logo\") --\u003e\n![Outformer Logo](./docs/img/logo_dark.png#gh-dark-mode-only \"Outformer Dark Logo\")\n![Outformer Logo](./docs/img/logo_light.png#gh-light-mode-only \"Outformer Light Logo\")\n\n# Outformer: Structure Outputs from Language Models\n\n[![PyPI - Package Version](https://img.shields.io/pypi/v/outformer?logo=pypi\u0026style=flat\u0026color=8c52ff)](https://pypi.org/project/outformer/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/outformer?logo=python\u0026logoColor=5ce1e6)](https://pypi.org/project/outformer/)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg?color=393be5)](https://github.com/milistu/outformer/blob/main/LICENSE)\n[![Docs - GitHub.io](https://img.shields.io/static/v1?logo=github\u0026style=flat\u0026color=5ce1e6\u0026label=docs\u0026message=outformer)](https://outformer.readthedocs.io/en/latest/)\n\nOutformer is a powerful library that enables language models to generate structured outputs. It ensures always valid JSON outputs by generating only values while maintaining the structural integrity of your schema.\n\n## Features\n\n- 🔄 **Structured Output Generation**: Generate valid JSON outputs from language models\n- 🎯 **Schema Validation**: Ensure outputs conform to your JSON schema\n- 🛠️ **Flexible Integration**: Works with any Hugging Face transformer model\n- 🚀 **Easy to Use**: Simple API with minimal configuration\n- 🎨 **Value Highlighting**: Visualize generated values in your JSON structure\n\n## Installation\n\nWe recommend **Python 3.10+, [PyTorch](https://pytorch.org/get-started/locally/) 2.7.0+, [transformers](https://github.com/huggingface/transformers) v4.51.3+**.\n\n### Install via pip\n```bash\npip install outformer\n```\n\n### Install from source\n```bash\ngit clone https://github.com/milistu/outformer.git\ncd outformer\npip install -e .\n```\n\n## Quick Start\n\nHere's a simple example to get you started:\n\n\u003c!-- ![Quick Start Example](https://raw.githubusercontent.com/milistu/outformer/main/docs/img/quick_start_light.png) --\u003e\n![Quick Start Example](./docs/img/quick_start_dark.png#gh-dark-mode-only)\n![Quick Start Example](./docs/img/quick_start_light.png#gh-light-mode-only)\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand code example\u003c/summary\u003e\n\n```python\nfrom outformer import Jsonformer, highlight_values\nfrom transformers import AutoModelForCausalLM, AutoTokenizer\n\n# Initialize model and tokenizer\nmodel_name = \"Qwen/Qwen3-1.7B\"\nmodel = AutoModelForCausalLM.from_pretrained(model_name)\ntokenizer = AutoTokenizer.from_pretrained(model_name)\n\n# Create Jsonformer instance\njsonformer = Jsonformer(model, tokenizer, max_tokens_string=30)\n\n# Define your JSON schema\njson_schema = {\n    \"type\": \"object\",\n    \"properties\": {\n        \"brand\": {\n            \"type\": \"string\",\n            \"description\": \"Brand of the product\",\n        },\n        \"model\": {\n            \"type\": \"string\",\n            \"description\": \"Model of the product\",\n        },\n        \"product_type\": {\n            \"type\": \"string\",\n            \"description\": \"Type of the product\",\n        },\n        \"gender\": {\n            \"type\": \"string\",\n            \"enum\": [\"Female\", \"Male\", \"Unisex\"],\n        },\n        \"color\": {\n            \"type\": \"string\",\n            \"description\": \"Color of the product if specified, otherwise return 'Unknown'\",\n        },\n        \"material\": {\n            \"type\": \"string\",\n            \"description\": \"Material of the product if specified, otherwise return 'Unknown'\",\n        },\n        \"features\": {\n            \"type\": \"array\",\n            \"minItems\": 3,\n            \"items\": {\n                \"type\": \"string\",\n                \"description\": \"Features of the product that may be relevant for the customer. Extract as much as possible.\",\n            },\n        },\n    },\n}\n\n# Your input prompt\nprompt = \"\"\"\nExtract key information from the product description:\n\nadidas Men's Powerlift.3 Cross-Trainer Shoes\nA powerful shoe with lockdown fit. Made with an extra-wide design that allows the foot to spread, these men's lifting/weight-training shoes pair a snug-fitting upper with a wide midfoot strap for extra support. A high-density die-cut wedge midsole keeps you close to the ground.\n100% Synthetic leather\nImported\nRubber sole\nRemovable Insole\n\"\"\"\n\n# Generate structured output\ngenerated_data = jsonformer.generate(schema=json_schema, prompt=prompt)\n\n# Highlight generated values\nhighlight_values(generated_data)\n```\n\nThe code above will generate a structured JSON output and display it with highlighted values. Here's what you'll get:\n\n```json\n{\n    \"brand\": \"Adidas\",\n    \"model\": \"Powerlift.3 Cross-Trainer Shoes\",\n    \"product_type\": \"Cross-Trainer Shoes\",\n    \"gender\": \"Male\",\n    \"color\": \"Unknown\",\n    \"material\": \"Synthetic leather\",\n    \"features\": [\n        \"Lockdown fit\",\n        \"Extra-wide design\",\n        \"High-density die-cut wedge midsole\",\n    ],\n}\n```\n\nWhen using `highlight_values()`, the output will be displayed in your terminal with the generated values highlighted in color, making it easy to distinguish between the structure and the generated content.\n\u003c/details\u003e\n\n## Advanced Usage\n\n### Configuration Options\n\nThe `Jsonformer` class accepts several configuration parameters:\n\n- `debug` (bool): Enable debug mode for detailed generation process\n- `max_array_length` (int): Maximum number of elements in an array\n- `max_tokens_number` (int): Maximum number of tokens for number generation\n- `max_tokens_string` (int): Maximum number of tokens for string generation\n- `temperature` (float): Sampling temperature for generation\n- `generation_marker` (str): Marker for tracking generation position\n- `max_attempts` (int): Maximum attempts for value generation\n\n### Supported JSON Schema Features\n\n- Basic types: string, number, boolean\n- Arrays with min/max items\n- Objects with nested properties\n- Enums for constrained string values\n- Descriptions for better generation context\n\n## Contributing\n\nWe welcome contributions! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Citing \u0026 Authors\n\nThe idea for this repository was inspired by [jsonformer](https://github.com/1rgs/jsonformer).\n\nMaintainer: [Milutin Studen](https://github.com/milistu)\n\n## Support\n\nIf you encounter any issues or have questions, please open an issue on our [GitHub repository](https://github.com/milistu/outformer/issues).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilistu%2Foutformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmilistu%2Foutformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmilistu%2Foutformer/lists"}