Skip to main content

Crate cordance_llm

Crate cordance_llm 

Source
Expand description

Cordance LLM adapters. Bounded candidate prose only. ADR 0002.

LLM output is never authority. Every claim must cite a source-ID from the input pack. Hard rules cannot originate here.

Enforced at the adapter level:

  • Local-only by default. Non-loopback Ollama URLs are rejected unless CORDANCE_ALLOW_REMOTE_LLM=1 is set in the operator’s environment.
  • Schema-bounded responses. Outputs deserialise into a fixed LlmCandidate shape; arbitrary text never escapes the adapter.
  • 4-gram source grounding. Every claim’s text must share at least one 4-gram with a cited source body, else the claim is rejected before the candidate leaves the adapter.
  • Hard rules dropped. ClaimType::HardRule and ClaimType::ProjectInvariant are filtered regardless of grounding — those classes can only come from doctrine, ADRs, or schemas.

§Golden path

use std::collections::HashMap;
use cordance_llm::{OllamaAdapter, OllamaSettings};

struct Cfg;
impl OllamaSettings for Cfg {
    fn base_url(&self) -> &str { "http://localhost:11434" }
    fn model(&self) -> &str { "qwen2.5-coder:14b" }
    fn temperature(&self) -> f32 { 0.1 }
    fn num_ctx(&self) -> u32 { 8192 }
}

let adapter = OllamaAdapter::from_config(&Cfg);
if !adapter.is_available() {
    eprintln!("Ollama not reachable at {}", adapter.base_url);
    return;
}

let prompt = "Summarise this project's main purpose in one paragraph.";
let cited_ids = vec!["project_readme:README.md".to_string()];
let source_bodies: HashMap<String, String> = HashMap::new();

let candidate = adapter
    .generate_with_grounding(prompt, &cited_ids, &source_bodies)
    .expect("ollama generate (grounded)");
println!("got {} grounded claims", candidate.claims.len());

Re-exports§

pub use candidate::ClaimType;
pub use candidate::LlmCandidate;
pub use candidate::LlmClaim;
pub use ollama::LlmError;
pub use ollama::OllamaAdapter;
pub use ollama::OllamaSettings;
pub use validator::validate;
pub use validator::validate_with_sources;

Modules§

candidate
cordance-llm-candidate.v1 schema.
ollama
Ollama adapter. ADR 0002: every response is validated as candidate-only before return.
prompt
Bounded prompt builder. Prompts produced here tell the model exactly which source IDs it may cite and forbid it from inventing facts or hard rules.
validator
Candidate validator. ADR 0002: hard-rule types, unknown source IDs, and ungrounded claims are all rejected before an LlmCandidate is returned.