Skip to main content

text-to-struct converts unstructured text into standardized, structured output

Project description

text-to-struct

PyPI version License: MIT Downloads LinkedIn

A Python package that transforms unstructured text inputs into structured, standardized outputs using LLM7 and llmatch-messages.

Overview

text_to_struct enables users to process textual descriptions, ideas, or concepts, and generate structured data adhering to a predefined format. It leverages the LLM7 language model via the langchain_llm7 package, combined with llmatch-messages to ensure the output matches specified patterns. This approach promotes consistency and ease of parsing, making the package particularly useful for content creation, brainstorming, and idea management systems.

Installation

pip install text_to_struct

Usage

from text_to_struct import text_to_struct

# Example usage with default LLM7
response = text_to_struct(user_input="Describe a new innovative app idea.")
print(response)

Parameters

  • user_input (str): The unstructured text to be processed.
  • llm (Optional[BaseChatModel]): An optional langchain LLM instance. If not provided, the default ChatLLM7 will be used.
  • api_key (Optional[str]): The API key for LLM7. If not provided, it will be fetched from the LLM7_API_KEY environment variable.

Available LLMs

You can pass your own LLM instances from various providers, such as:

Using langchain's OpenAI

from langchain_openai import ChatOpenAI
from text_to_struct import text_to_struct

llm = ChatOpenAI()
response = text_to_struct(user_input, llm=llm)

Using langchain's Anthropic

from langchain_anthropic import ChatAnthropic
from text_to_struct import text_to_struct

llm = ChatAnthropic()
response = text_to_struct(user_input, llm=llm)

Using langchain's Google Generative AI

from langchain_google_genai import ChatGoogleGenerativeAI
from text_to_struct import text_to_struct

llm = ChatGoogleGenerativeAI()
response = text_to_struct(user_input, llm=llm)

API Key & Rate Limits

The default free-tier rate limits for LLM7 are sufficient for most use cases. To access higher rate limits, set your API key via:

  • Environment variable: LLM7_API_KEY
  • Or pass directly: text_to_struct(user_input, api_key="your_api_key")

You can obtain a free API key at https://token.llm7.io/.

Development & Support

Source Code

The core functionality is built on the langchain_llm7 package (available on PyPI), which interfaces with LLM7. The package also uses llmatch_messages for pattern matching and ensuring output structure.


Note: The text_to_struct function relies on a pattern matching regex and specific prompts (system_prompt and human_prompt) to guide the LLM output. Make sure your input and patterns align with your expected structured output.

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

text_to_struct-2025.12.22084055.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

text_to_struct-2025.12.22084055-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file text_to_struct-2025.12.22084055.tar.gz.

File metadata

File hashes

Hashes for text_to_struct-2025.12.22084055.tar.gz
Algorithm Hash digest
SHA256 cf10a604b9da22c745398fbc1febb9ebee852c9a2b1492b583544a8f8e7b8db8
MD5 25ed0c0c24eb079fcd219bcfe320bb5c
BLAKE2b-256 087a9066a79ab5d3b12a9ffc86d80d8ac89815ac58c032239d986b2c892ecef1

See more details on using hashes here.

File details

Details for the file text_to_struct-2025.12.22084055-py3-none-any.whl.

File metadata

File hashes

Hashes for text_to_struct-2025.12.22084055-py3-none-any.whl
Algorithm Hash digest
SHA256 b16c40224dd4e91957dc936ad617de7d29e5911ff9fb9b40e673ece6bb72e929
MD5 898a2d38ee150a2585df76e6c9a3c82a
BLAKE2b-256 193fa5283af616afb44a41d3c5d56a1f91cca2d4f5542a635fcf4a1bd5c6b8a7

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