Skip to main content

LLMbo - Large Language model batch operations

AWS Bedrock offers powerful capabilities for running batch inference jobs with large language models. However, orchestrating these jobs, managing inputs and outputs, and ensuring consistent result structures can be arduous. LLMbo aims to solve these problems by providing an intuitive, Pythonic interface for Bedrock batch operations.

Additionally, it provides a method of using batch inference for structured responses, taking inspiration from the likes of instructor, mirascope and pydanticai. You provide a model output as a pydantic model and llmbo creates takes care of the rest.

See the AWS documentation for models that support batch inference.

The library includes built-in adapters for the following model families:

Adapter Models Approach
AnthropicAdapter Claude (Anthropic) Native tool use
MistralAdapter Mistral / Mixtral (legacy prompt injection) JSON extraction from text
MistralFunctionAdapter Mistral / Mixtral (function calling) Native tool use
OpenAIAdapter OpenAI-compatible models Native tool use
DeepSeekAdapter DeepSeek Native tool use
QwenAdapter Alibaba Qwen Native tool use
LlamaAdapter Meta Llama 3 / 4 JSON extraction from text
NovaAdapter Amazon Nova (Converse API) Native tool use

Adapters are auto-selected at runtime based on the model ID you pass to BatchInferer. Other models may be supported through the default adapter, or you can write and register your own (see src/llmbo/adapters/base.py).

Prerequisites

  • A .env file with an entry for AWS_PROFILE=. This profile should have sufficient permissions to create and schedule a batch inference job. See the AWS instructions
  • A service role with the required permissions to execute the job.,
  • A s3 bucket to store the input and outputs for the job. S3 buckets must exists in the same region as you execute the job. This is a limitation of AWS batch inference rather that the package.
    • Inputs will be written to f{s3_bucket}/input/{job_name}.jsonl
    • Outputs will be written to f{s3_bucket}/output/{job_id}/{job_name}.jsonl.out and f{s3_bucket}/output/{job_id}/manifest.json.out

Install

pip install llmbo-bedrock

Getting started

Here's a quick example of how to use LLMbo:

BatchInferer

from llmbo import BatchInferer, ModelInput

bi = BatchInferer(
    model_name="anthropic.claude-v2",
    bucket_name="my-inference-bucket",
    region="us-east-1",
    job_name="example-batch-job",
    role_arn="arn:aws:iam::123456789012:role/BedrockBatchRole"
)

# Prepare your inputs using the ModelInput class, you also need to include an id 
# input Dict[job_id: ModelInput ]

inputs = {
    f"{i:03}": ModelInput(
        messages=[{"role": "user", "content": f"Question {i}"}]
    ) for i in range(100)
}


# Run the batch job, this prepares, uploads, creates the job, monitors the progress 
# and downloads the results
results = bi.auto(inputs)

StructuredInferer

For structured inference, simply define a Pydantic model and use StructuredBatchInferer:

from pydantic import BaseModel
from llmbo import StructuredBatchInferer

class ResponseSchema(BaseModel):
    answer: str
    confidence: float

sbi = StructuredBatchInferer(
    output_model=ResponseSchema,
    model_name="anthropic.claude-v2",
    # ... other parameters
)

# The results will be validated against ResponseSchema
structured_results = sbi.auto(inputs)

For more detailed examples see the followingin llmbo.py:

  • examples/batch_inference_example.py: for an example of free text response
  • examples/structured_batch_inference_example.py: for an example of structured response ala instructor

Release files for llmbo-bedrock 0.2.4

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

Source distribution (sdist)

Source distribution for llmbo-bedrock 0.2.4
File Size Uploaded
llmbo_bedrock-0.2.4.tar.gz 114.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llmbo-bedrock 0.2.4
File Interpreter ABI Platform
llmbo_bedrock-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 148.6 kB

Release files / llmbo_bedrock-0.2.4.tar.gz

Download URL llmbo_bedrock-0.2.4.tar.gz
Size 114.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fd1f836b1395c2acb5842c7d07c743d21e0100c816791412eb97e64cc2eab2e5
BLAKE2b-256 checksum
How to use checksums
f7e81448cff0f87d3802ea432255e197b5a4395ddea0e0126baba8166e3a0ca7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llmbo_bedrock-0.2.4-py3-none-any.whl

Download URL llmbo_bedrock-0.2.4-py3-none-any.whl
Size 33.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6af6526db5bc297062980a6542b1df8a331950340d04ef3dc3142464370d68f
BLAKE2b-256 checksum
How to use checksums
27a0a58b7c57a2ddc3990afd3137b16c15ace255376b0b40fc8cb41266bdc36b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

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