Skip to main content

ollama-json-fixer-python

Force local Ollama models to output strict, valid JSON. Zero dependencies beyond requests.

Python 3.8+ License: MIT Ollama Compatible GPU: RTX 3060 Tested

Problem

Local LLMs (Llama 3, Mistral, Qwen, Codellama) often wrap JSON in conversational text or markdown fences, breaking json.loads(). This causes JSONDecodeError in production pipelines.

Solution

  • Auto-strips markdown fences
  • Regex extraction of JSON blocks
  • Auto-retry with strict system prompt
  • Works with ANY Ollama model
  • Single file - just copy and use

Quick Start

pip install requests
python ollama_json_fixer.py

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ollama_json_fixer-0.1.0.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ollama_json_fixer-0.1.0-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file ollama_json_fixer-0.1.0.tar.gz.

File metadata

  • Download URL: ollama_json_fixer-0.1.0.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.6

File hashes

Hashes for ollama_json_fixer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eead9f4b75e92c7de5e12a17436a058363bc105f44f95f999e2a38d2b247c195
MD5 dd7d7400be31c910eec5c81402259a89
BLAKE2b-256 a76cbf5d6af7a7c9bcc748476b017d18c687e0da8e5ff97ba5223268b28d7f30

See more details on using hashes here.

File details

Details for the file ollama_json_fixer-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ollama_json_fixer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d946defcb8666a437fc00b99bec517c24daa439d4e8f52c361aaccc05da34e1
MD5 4ba0ca09814380116ebc5dc3215e2e96
BLAKE2b-256 cff77c8fe96e1a1369501a4cd300accae7051e0a25a13ccbcbd55dda656aef9a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page