Skip to main content Switch to mobile version kiln-ai 1.3.0 Kiln AI
pip install kiln-ai==1.3.0 Copy PIP instructions
pip install kiln_ai About
This package is the Kiln AI core library. There is also a separate desktop application and server package. Learn more about Kiln AI at kiln.app and on Github: github.com/Kiln-AI/kiln.
In this guide we'll walk common examples of how to use the library.
The library has a comprehensive set of docs.
Connecting AI Providers
Using the Kiln Data Model Understanding the Kiln Data Model
Run a Kiln Task from Python
Load an Existing Dataset into a Kiln Task Dataset
Using your Kiln Dataset in a Notebook or Project
Using Kiln Dataset in Pandas
Caching Loaded Records
Building and Running a Kiln Task from Code
Tagging Task Runs Programmatically
Adding Custom Model or AI Provider from Code
Taking Kiln RAG to production Load a LlamaIndex Vector Store
Example: LanceDB Cloud
Deploy RAG without LlamaIndex
Connecting to Telemetry / MLOps
pip install kiln-ai Connecting AI Providers (OpenAI, OpenRouter, Ollama, etc)
The easiest way to connect AI providers is to use the Kiln app UI. Once connected in the UI, credentials will be stored to ~/.kiln_ai/settings.yaml, which will be available to the library.
For configuring credentials from code or connecting custom servers/model, see Adding Custom Model or AI Provider from Code.
Using the Kiln Data Model
Understanding the Kiln Data Model
Kiln projects are simply a directory of files (mostly JSON files with the extension .kiln) that describe your project, including tasks, runs, and other data.
This dataset design was chosen for several reasons:
Git compatibility: Kiln project folders are easy to collaborate on in git. The filenames use unique IDs to avoid conflicts and allow many people to work in parallel. The files are small and easy to compare using standard diff tools.
JSON allows you to easily load and manipulate the data using standard tools (pandas, polars, etc)
The Kiln Python library provides a set of Python classes that which help you easily interact with your Kiln dataset. Using the library to load and manipulate your dataset is the fastest way to get started, and will guarantees you don't insert any invalid data into your dataset. There's extensive validation when using the library, so we recommend using it to load and manipulate your dataset over direct JSON manipulation.
Here's a high level overview of the Kiln datamodel. A project folder will reflect this nested structure:
Project: a Kiln Project that organizes related tasks Task: a specific task including prompt instructions, input/output schemas, and requirements TaskRun: a sample (run) of a task including input, output and human rating information
Finetune: configuration and status tracking for fine-tuning models on task data
Prompt: a prompt for this task
DatasetSplit: a frozen collection of task runs divided into train/test/validation splits
Assuming you've created a project in the Kiln UI, you'll have a project.kiln file in your ~/Kiln Projects/Project Name directory.
from kiln_ai.datamodel import Project project = Project.load_from_file("path/to/your/project.kiln") print("Project: ", project.name, " - ", project.description) # List all tasks in the project, and their dataset sizes tasks = project.tasks() for task in tasks: print("Task: ", task.name, " - ", task.description) print("Total dataset size:", len(task.runs())) Run a Kiln Task from Python
If you've already created a Kiln task and want to run it as part of a Python app you can follow this example.
Step 1: Export your Kiln task/project
You can run any Kiln task from code using it's project file/folder on disk. However, these folders can contain thousands of files relating to past runs and evals, which is more than you probably want to deploy to a service. Only a few of these files are needed for running the task: you can export a minimal project folder with on the necessary files to run a task by running our CLI:
uvx kiln_ai package_project "/path/to/your/project.kiln" -t TASK_ID_TO_EXPORT Step 2: Run Kiln Task from Code
Already have a Kiln Task created and saved to disk at TASK_PATH. It doesn't matter if you created it using the Kiln app, the Kiln library, or exported it using the command above.
Set a default run configuration in the Kiln UI specifying how to run the task: model, AI provider, etc. Alternatively you can create a RunConfigProperties instance in code.
Set up any API keys required for the task. If running on the same machine as the Kiln app, these will already be saved in ~/.kiln_ai/settings.yaml and will be loaded automatically. If running on a server, you can set the required environment variables (see libs/core/kiln_ai/utils/config.py for a list).
If your task uses RAG, ensure you have run search indexing on this machine with the Kiln UI or via the library.
from kiln_ai.adapters.adapter_registry import adapter_for_task from kiln_ai.datamodel.task import Task async def run_kiln_task(input: str) -> dict[str, Any] | str: # Load your task from it's path on the filesystem task = Task.load_from_file(TASK_PATH) # Here we get the default run config from the task, which you can set in the UI. Alternatively you could pass a RunConfigProperties object with parameters like the model, temperature, etc. run_config = next(c for c in task.run_configs() if c.id == task.default_run_config_id) # An adapter can run a task adapter = adapter_for_task( task, run_config_properties=run_config.run_config_properties, ) task_run, run_output = await adapter.invoke_returning_run_output(input) # Optional: can inspect the task run to see usage data (cost, tokens, etc.) #print(f"Task run cost: {task_run.usage.cost}") return run_output.output Load an Existing Dataset into a Kiln Task Dataset
If you already have a dataset in a file, you can load it into a Kiln project.
Important: Kiln will validate the input and output schemas, and ensure that each datapoint in the dataset is valid for this task.
Plaintext input/output: ensure "output_json_schema" and "input_json_schema" not set in your Task definition.
JSON input/output: ensure "output_json_schema" and "input_json_schema" are valid JSON schemas in your Task definition. Every datapoint in the dataset must be valid JSON fitting the schema.
Here's a simple example of how to load a dataset into a Kiln task:
import kiln_ai import kiln_ai.datamodel # Created a project and task via the UI and put its path here task_path = "/Users/youruser/Kiln Projects/test project/tasks/632780983478 - Joke Generator/task.kiln" task = kiln_ai.datamodel.Task.load_from_file(task_path) # Add data to the task - loop over you dataset and run this for each item item = kiln_ai.datamodel.TaskRun( parent=task, input='{"topic": "AI"}', output=kiln_ai.datamodel.TaskOutput( output='{"setup": "What is AI?", "punchline": "content_here"}', ), ) item.save_to_file() print("Saved item to file: ", item.path) And here's a more complex example of how to load a dataset into a Kiln task. This example sets the source of the data (human in this case, but you can also set it be be synthetic), the created_by property, and a 5-star rating.
You can use your Kiln dataset in a notebook or project by loading the dataset into a pandas dataframe.
You can also use your Kiln dataset in a pandas dataframe, or a similar script for other tools like polars.
import glob import json import pandas as pd from pathlib import Path task_dir = "/Users/youruser/Kiln Projects/test project/tasks/632780983478 - Joke Generator" dataitem_glob = task_dir + "/runs/*/task_run.kiln" dfs = [] for file in glob.glob(dataitem_glob): js = json.loads(Path(file).read_text()) df = pd.DataFrame([{ "input": js["input"], "output": js["output"]["output"], }]) # Alternatively: you can use pd.json_normalize(js) to get the full json structure # df = pd.json_normalize(js) dfs.append(df) final_df = pd.concat(dfs, ignore_index=True) print(final_df) Caching Loaded Records
By default, the library reads and validates a record from disk each time you load it. If your code loads the same records many times, for example a notebook that calls task.runs() in several cells, turn on the cache that the Kiln app uses:
from kiln_ai.datamodel import set_model_cache_enabled set_model_cache_enabled(True) runs = task.runs(readonly=True) With the cache on, readonly loads (readonly=True) keep each record in memory and return it again until its file changes on disk. Readonly records are shared, so assigning to one raises an error. Load without readonly=True to get a copy you can edit and save.
The cache keeps its memory under 2 GB or 20% of RAM, whichever is smaller. To stay under it, the cache can drop the large fields of a record, such as a run's input, output and trace, and read them back from disk the next time your code uses them. set_model_cache_enabled(False) turns the cache off and empties it.
ModelCache.shared().disable() (from kiln_ai.datamodel.model_cache) turns it off and empties it for the rest of the process: a later set_model_cache_enabled(True) leaves it off. The Kiln app, kiln_server and kiln_mcp do this at startup when KILN_DISABLE_MODEL_CACHE=true is set, and turn the cache on otherwise. The library itself never reads that variable.
# Step 1: Create or Load a Task -- choose one of the following 1.A or 1.B # Step 1.A: Optionally load an existing task from disk # task = datamodel.Task.load_from_file("path/to/task.kiln") # Step 1.B: Create a new task in code, without saving to disk. task = datamodel.Task( name="test task", instruction="Tell a joke, given a subject.", ) # replace with a valid JSON schema https://json-schema.org for your task (json string, not a python dict). # Or delete this line to use plaintext output task.output_json_schema = json_joke_schema # Step 2: Create an Adapter to run the task, with a specific model and provider adapter = adapter_for_task(task, model_name="llama_3_1_8b", provider="groq") # Step 3: Invoke the Adapter to run the task task_input = "cows" response = await adapter.invoke(task_input) print(f"Output: {response.output.output}") # Step 4 (optional): Load the task from disk and print the results. # This will only work if the task was loaded from disk, or you called task.save_to_file() before invoking the adapter (ephemeral tasks don't save their result to disk) task = datamodel.Task.load_from_file(tmp_path / "test_task.kiln") for run in task.runs(): print(f"Run: {run.id}") print(f"Input: {run.input}") print(f"Output: {run.output}") Tagging Task Runs Programmatically
You can also tag your Kiln Task runs programmatically:
# Load your Kiln Task from disk task_path = "/Users/youruser/Kiln Projects/test project/tasks/632780983478 - Joke Generator/task.kiln" task = kiln_ai.datamodel.Task.load_from_file(task_path) for run in task.runs(): # Parse the task output from JSON output = json.loads(run.output.output) # Add a tag if the punchline is unusually short if len(output["punchline"]) < 100: run.tags.append("very_short") run.save_to_file() # Persist the updated tags Adding Custom Model or AI Provider from Code
You can add additional AI models and providers to Kiln.
See our docs for more information, including how to add these from the UI:
Custom Models From Existing Providers
Custom OpenAI Compatible Servers
You can also add these from code. The kiln_ai.utils.Config class helps you manage the Kiln config file (stored at ~/.kiln_ai/settings.yaml):
# Adding an OpenAI compatible provider name = "CustomOllama" base_url = "http://localhost:1234/api/v1" api_key = "12345" providers = Config.shared().openai_compatible_providers or [] existing_provider = next((p for p in providers if p["name"] == name), None) if existing_provider: # skip since this already exists return providers.append( { "name": name, "base_url": base_url, "api_key": api_key, } ) Config.shared().openai_compatible_providers = providers # Add a custom model ID to an existing provider. new_model = "openai::gpt-3.5-turbo" custom_model_ids = Config.shared().custom_models existing_model = next((m for m in custom_model_ids if m == new_model), None) if existing_model: # skip since this already exists return custom_model_ids.append(new_model) Config.shared().custom_models = custom_model_ids Taking Kiln RAG to production
When you're ready to deploy your RAG system, you can export your processed documents to any vector store supported by LlamaIndex. This allows you to use your Kiln-configured chunking and embedding settings in production.
Load a LlamaIndex Vector Store
Kiln provides a VectorStoreLoader that yields your processed document chunks as LlamaIndex TextNode objects. These nodes contain the same metadata, chunking and embedding data as your Kiln Search Tool configuration.
Internally Kiln uses LanceDB. By using LanceDB cloud you'll get the same indexing behaviour as in app.
Here's a complete example using LanceDB Cloud:
While Kiln is designed for deploying to LlamaIndex, you don't need to use it. The iter_llama_index_nodes returns a TextNode object which includes all the data you need to build a RAG index in any stack: embedding, text, document name, chunk ID, etc.
Connecting to Telemetry / MLOps (OpenTelemetry, Braintrust, etc)
You can connect the Kiln SDK to a wide range of MLOps, trace tracking, and telemetry platforms.
Kiln uses the LiteLLM SDK, which supports all major telemetry providers. See LiteLLM's documentation for how to set up each provider:
Many more (see LiteLLM documentation)
The library can do a lot more than the examples we've shown here.
See the full API reference in the docs under the Submodules section of the sidebar.
Released: Dec 3, 2026
Author: Steve Cosman, Chesterfield Laboratories Inc
Intended Audience Developers
License OSI Approved :: MIT License
Programming Language Python :: 3.11
Release files for kiln-ai 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 3.8 MB
Release files / kiln_ai-1.3.0.tar.gz
Release files / kiln_ai-1.3.0-py3-none-any.whl
Security for kiln-ai 1.3.0
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.
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.
Release history Release notifications | RSS feed
Dec 3, 2026 2 release files No provenance
Nov 11, 2026 2 release files No provenance
Sep 29, 2026 2 release files No provenance
Sep 16, 2026 2 release files No provenance
Aug 20, 2026 2 release files No provenance
Jul 16, 2026 2 release files No provenance
Jun 23, 2026 2 release files No provenance
May 11, 2026 2 release files No provenance
Apr 22, 2026 2 release files No provenance
Mar 18, 2026 2 release files No provenance
Feb 20, 2026 2 release files No provenance
Jan 28, 2026 2 release files No provenance
Jan 19, 2026 2 release files No provenance
Nov 13, 2025 2 release files No provenance
Oct 7, 2025 2 release files No provenance
Oct 6, 2025 2 release files No provenance
Sep 22, 2025 2 release files No provenance
Sep 9, 2025 2 release files No provenance
Aug 8, 2025 2 release files No provenance
Jul 15, 2025 2 release files No provenance
Jun 15, 2025 2 release files No provenance
May 17, 2025 2 release files No provenance
Apr 23, 2025 2 release files No provenance
Apr 5, 2025 2 release files No provenance
Mar 22, 2025 2 release files No provenance
Mar 18, 2025 2 release files No provenance
Mar 3, 2025 2 release files No provenance
Feb 10, 2025 2 release files No provenance
Dec 20, 2024 2 release files No provenance
Dec 15, 2024 2 release files No provenance
Dec 7, 2024 2 release files No provenance
Nov 20, 2024 2 release files No provenance
Nov 19, 2024 2 release files No provenance
Nov 5, 2024 2 release files No provenance
Nov 4, 2024 2 release files No provenance
Oct 30, 2024 2 release files No provenance
Oct 24, 2024 2 release files No provenance
Aug 19, 2024 2 release files No provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation
Deployed from 4d99e05











