Consensus
What is “consensus”?
Consensus is about asking several language‑model instances the same question in parallel, then merging their structured outputs into a single, consolidated result.
Consensus offers higher reliability for extraction tasks, zero‑shot majority voting, uncertainty quantification, and automatic guard‑rail against hallucination—without changing your business logic.
Related to Palantir’s K-LLM strategy: This approach follows similar principles to Palantir’s “K-LLMs” methodology, where multiple models evaluate the same prompt and their outputs are synthesized for increased accuracy, confidence, and reduced hallucinations. Like Palantir’s approach, UiForm’s consensus mechanism helps mitigate biases from any single model while providing flexibility across different LLM providers.
How it works
Under the hood UiForm:
-
Fires n_consensus identical calls.
-
Parses each raw answer into a Pydantic model / JSON‑Schema object.
-
Runs a deterministic reconciliation strategy
- Exact match vote for scalar fields.
- Deep merge for arrays / objects when all candidates agree on shape.
-
Returns the reconciled object in
response.output_parsed
(Responses) orcompletion.choices[0].message.parsed
(Completions).
If any response fails JSON validation the call is retried once; after that a ConsensusError
is raised.
We provide a quick, type‑safe wrapper around OpenAI Chat Completions and Responses endpoints with automatic consensus reconciliation.
-
Step 1: Generating diverse answers. We purposely sample each call with
temperature > 0
to obtain distinct answers. -
Step 2: SOTA reconciliation. A bespoke, finetuned LLM (code‑name
reconcile‑v1
) performs fuzzy string matching and majority‑vote reasoning to merge the candidates with state‑of‑the‑art accuracy.
Quick‑Start: Switch in One Line
Everything else (models, schema, temperature, etc.) stays untouched.
Completions API
Method | Description |
---|---|
client.consensus.completions.parse(...) | Chat completion that returns a parsed object plus the raw OpenAI response. |
Minimum Arguments
Name | Type | Default | Notes |
---|---|---|---|
model | str | — | Any OpenAI chat model name. |
messages | list[dict] | — | Same shape as OpenAI’s messages . |
response_format | pydantic.BaseModel or dict JSON‑Schema | — | Target structure. |
n_consensus | int | 1 | >1 enables consensus. |
Example
Responses API
Use when you have a single prompt + single expected answer (e.g., function‑calling, multi‑step reasoning).
Method | Description |
---|---|
client.consensus.responses.parse(...) | Thin wrapper for the /responses endpoint; consensus works the same way. |
Arguments
Same as Completions API: model
, input
, text_format|text_schema
, n_consensus
.
Example
Reconcile API
Method | Description |
---|---|
client.consensus.reconcile(...) | Direct access to reconcile multiple dictionaries into a single consensus result. |
Arguments
Name | Type | Default | Notes |
---|---|---|---|
list_dicts | list[dict] | — | List of dictionaries to reconcile. |
reference_schema | dict | None | Optional schema to validate dictionaries against. |
mode | Literal["direct", "aligned"] | "direct" | Mode for consensus computation. |
idempotency_key | str | None | Optional idempotency key for the request. |