Skip to content

ontocast.onto.llm_graph_payload

Strict LLM wire coercion for RDF graph fields on canonical Pydantic models.

coerce_llm_graph_wire(value, info)

Coerce LLM wire payloads to RDFGraph using validation context or ContextVar.

Source code in ontocast/onto/llm_graph_payload.py
def coerce_llm_graph_wire(value: Any, info: ValidationInfo) -> RDFGraph:
    """Coerce LLM wire payloads to RDFGraph using validation context or ContextVar."""
    ctx = info.context if info.context else {}
    fmt = ctx.get("llm_graph_format") or llm_graph_format_ctx.get()
    if fmt == LLMGraphFormat.TURTLE:
        return _coerce_turtle_graph_payload(value)
    return _coerce_jsonld_graph_payload(value)