Skip to main content

llmutil

This library provides tools to generate structured output and function calling from the OpenAI API.

What is Structured Output?

Structured Output is the recommended method for getting formatted responses. It guarantees that outputs follow your defined schema, making it more reliable than previous methods like JSON mode, function calls, or tool use.

How to Use

Structured Output

To use Structured Output, you need to define a schema using a simple dictionary format:

from llmutil import new_response

output = new_response(
    [
        {
            "role": "user",
            "content": "normalize this address: 1 hacker way, menlo park, california",
        }
    ],
    model="gpt-4.1-mini",
    schema={
        "street": "string",
        "city": "string",
        "state": "string",
    },
)
# {'street': '1 Hacker Way', 'city': 'Menlo Park', 'state': 'CA'}

Function Calling

For function calling, implement the Tooling protocol to define available functions:

from llmutil import Result, Tooling, new_response

def add(a, b):
    return a + b

class UseAdd(Tooling):
    def on_function_call(self, name, args):
        if name == "add":
            return Result(add(args["a"], args["b"]))

    def get_tools(self):
        return {
            "add": {
                "a": "number",
                "b": "number",
            }
        }

messages = [
    {
        "role": "system",
        "content": "you cannot do math. you must use the add() function to add numbers.",
    },
    {
        "role": "user",
        "content": "alice has 10 apples, bob has 20 apples, how many apples do they have in total?",
    },
]

output = new_response(messages, model="gpt-4.1-mini", tooling=UseAdd())
# Alice and Bob have 30 apples in total.

API Reference

new_response(messages, *, model, tooling=None, schema=None, memory=None, timeout=30)

Main function for generating responses from OpenAI API.

  • messages: List of message dictionaries in OpenAI format
  • model: OpenAI model name (e.g., "gpt-4.1-mini")
  • tooling: Optional Tooling implementation for function calling
  • schema: Optional dictionary defining the output schema
  • memory: Optional vector store ID for file search
  • timeout: Request timeout in seconds (default: 30)

Tooling Protocol

Protocol for implementing function calling:

  • on_function_call(self, name: str, args: dict): Handle function calls, return Result to continue or any other value to return immediately
  • get_tools(self): Return dictionary mapping function names to parameter schemas

Result Class

Wrapper for function call results that should continue the conversation:

  • Result(result): Wrap a result to continue the conversation flow

Metadata

Release files for bfg-llmutil 0.5.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bfg-llmutil 0.5.5
File Size Uploaded Provenance
bfg_llmutil-0.5.5.tar.gz 9.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bfg-llmutil 0.5.5
File Interpreter ABI Platform
bfg_llmutil-0.5.5-py3-none-any.whl Python 3 none any Details

Total release size: 17.7 kB

Release files / bfg_llmutil-0.5.5.tar.gz

Download URL bfg_llmutil-0.5.5.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
201cb9f2275e0273295ef309f275477002e460be5c29e861a4e5e7dbb8fbb897
BLAKE2b-256 checksum
How to use checksums
00ba4ce582dc7e2d2ba5455d5db5e4ffb0a22fa1e582833401d34a771c220fd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.9

Release files / bfg_llmutil-0.5.5-py3-none-any.whl

Download URL bfg_llmutil-0.5.5-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
867f28db8fa1ef16701bdd2d214de1765d136a17098948cd7f7fbc62679b7074
BLAKE2b-256 checksum
How to use checksums
5f8b5e72cd894e08d636bd8350ff4b468f32be7f53c34918a83b03a318f5ab56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.9

Security for bfg-llmutil 0.5.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page