Skip to main content

A Python package for converting unstructured text into JSONL format using LLMs.

Project description

PyPI version License: MIT Downloads LinkedIn

llm_jsonl_converter

This Python package provides functionality to convert unstructured text into JSONL (JSON Lines) format using a Large Language Model (LLM). It intelligently chunks text, prompts the LLM to generate JSON objects conforming to specified formats, and validates the output to produce a clean JSONL string.

Features

  • LLM-Powered Conversion: Leverages LLMs to extract structured data from free-form text.
  • JSONL Output: Generates data in the widely-used JSON Lines format.
  • Configurable Formats: Supports defining and using custom JSONL schemas.
  • Chunking Strategy: Divides large texts into manageable chunks for LLM processing.
  • Validation: Ensures generated JSON lines conform to a specified regex pattern.
  • Progress Indication: Uses tqdm for a visual progress bar during conversion.

Installation

To install llm_jsonl_converter, use pip:

pip install llm_jsonl_converter

Usage

The primary function is generate_jsonl_from_text. You need to provide the text to convert and the name of the target JSONL format.

from llm_jsonl_converter import generate_jsonl_from_text
from langchain_llm7 import ChatLLM7 # Or any other compatible BaseChatModel

# Initialize your LLM (replace with your actual LLM setup if needed)
# If llm is None, a default ChatLLM7 instance will be used.
llm_instance = ChatLLM7(
    model="gemini-2.5-flash-lite",
    base_url="https://api.llm7.io/v1"
)

# Example unstructured text
sample_text = """
John Doe is a software engineer based in New York. He works at Tech Innovations Inc.
His email is john.doe@example.com and his phone number is 123-456-7890.
He has over 5 years of experience in Python and JavaScript.
Jane Smith is a data scientist from San Francisco. She can be reached at jane.smith@company.org.
Her expertise lies in machine learning and statistical analysis.
"""

# Define the target format name (ensure this format is available via get_llm_jsonl_formats())
target_format = "OpenAI Prompt–Completion (SFT)"

try:
    jsonl_output = generate_jsonl_from_text(
        text=sample_text,
        target_format_name=target_format,
        llm=llm_instance,
        chunk_word_size=150, # Adjust chunk size as needed
        verbose=True # Set to True for detailed logs
    )
    print(jsonl_output)
except ValueError as e:
    print(f"Error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

License

llm_jsonl_converter is licensed under the MIT License.

Author

Eugene Evstafev hi@eugene.plus Repository: https://github.com/chigwell/llm_jsonl_converter

Project details


Download files

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

Source Distribution

llm_jsonl_converter-2025.9.111721.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

llm_jsonl_converter-2025.9.111721-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file llm_jsonl_converter-2025.9.111721.tar.gz.

File metadata

File hashes

Hashes for llm_jsonl_converter-2025.9.111721.tar.gz
Algorithm Hash digest
SHA256 6f7b24ceb9ae8732c9cbbca40beb3bd96ed80e0b567a61bae072464636a1a735
MD5 20dc1d8beb425823a44d179cd7ec7df8
BLAKE2b-256 f5a09e917be76a652e4c1dc44485f86df3d7b0292f0b6a4694872f54446f66e4

See more details on using hashes here.

File details

Details for the file llm_jsonl_converter-2025.9.111721-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_jsonl_converter-2025.9.111721-py3-none-any.whl
Algorithm Hash digest
SHA256 689fd87e4b5d762c3a987a41c02cd045f0cdccdaf1bbb90bda0247b65342777f
MD5 a3cab52d82395c5c536ea6cf5cd2b996
BLAKE2b-256 24bcf6224d88a7ff26e3511f257a12c49ee0cd384932cb183cb05fd48a330b1a

See more details on using hashes here.

Supported by

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