01
Sample independent outputs
Set n above 1 to generate candidates from the same prompt.
Loading…
Consensus flow
Run independent generations, align the structured candidates, and produce one parsed result with likelihoods.
01
Set n above 1 to generate candidates from the same prompt.
02
Match equivalent objects and list items before comparison.
03
Return parsed data plus likelihoods shaped like the schema.
Basic usage
k-LLMs keeps the OpenAI parse shape. Set n above 1, read the reconciled result from choices[0], and keep alternative candidates in the remaining choices.
Retab extraction APIs expose the same control as n_consensus.
For arrays and nested objects, alignment happens before scoring so order changes do not erase equivalent items.
Operational reliability
Single-run extraction hides ambiguity. k-LLMs makes disagreement explicit by returning likelihoods that mirror your schema.
Use those scores as routing inputs: high-confidence fields can flow through automatically, while uncertain fields go to validation or human review.
from k_llms import KLLMs
from pydantic import BaseModel
class Event(BaseModel):
name: str
date: str
participants: list[str]
client = KLLMs()
response = client.chat.completions.parse(
model="gpt-5.5",
messages=[
{
"role": "user",
"content": "Alice and Bob are going to a science fair on Friday.",
}
],
response_format=Event,
n=4,
)
event = response.choices[0].message.parsed
scores = response.likelihoods
alternatives = response.choices[1:]