Skip to content

ontocast.prompt.facts_guidelines

Facts rendering operational guidelines (format-specific).

format_facts_operational_guidelines(*, facts_namespace, domain_ontologies_clause, jsonld, quantity_fallback_vocabulary=None, search_guidelines='')

Build operational guidelines for the active graph format.

Source code in ontocast/prompt/facts_guidelines.py
def format_facts_operational_guidelines(
    *,
    facts_namespace: str,
    domain_ontologies_clause: str,
    jsonld: bool,
    quantity_fallback_vocabulary: dict[str, str] | None = None,
    search_guidelines: str = "",
) -> str:
    """Build operational guidelines for the active graph format."""
    literal_rules = facts_literal_rules_jsonld if jsonld else facts_literal_rules_turtle
    hygiene = facts_output_hygiene_jsonld if jsonld else facts_output_hygiene_turtle
    guidelines = facts_instruction_shared.format(
        domain_ontologies_clause=domain_ontologies_clause,
        facts_namespace=facts_namespace,
        literal_encoding_rules=literal_rules,
        output_hygiene_rule=hygiene,
        quantity_fallback_clause=format_quantity_fallback_clause(
            quantity_fallback_vocabulary
            if quantity_fallback_vocabulary is not None
            else DEFAULT_QUANTITY_FALLBACK_VOCABULARY
        ),
        search_guidelines=search_guidelines,
    )
    if jsonld:
        # 10a., not 11. or 12.: rule 11 is the conditional search guideline
        # injected above and is absent whenever web grounding is off, so a fixed
        # number either collides with it or leaves a gap in the default prompt.
        # The template already uses this suffix convention for 1a. and 6a.
        guidelines += (
            "\n10a. In structured output, express facts as a JSON-LD object "
            "(`@context` + `@graph`), not as a Turtle string. "
            "Map the examples above to compact IRIs and JSON-LD literal objects.\n"
        )
    return guidelines

format_quantity_fallback_clause(vocabulary)

Render the bounded-quantity fallback for a configured vocabulary.

The fallback is what the renderer reaches for when retrieval supplied no bounded-quantity class. Which vocabulary that is belongs to the deployment, not to the prompt: a catalog modelling quantities with anything other than QUDT would otherwise be told to emit QUDT terms it never declared.

Parameters:

Name Type Description Default
vocabulary dict[str, str]

Role -> term mapping (FACTS_QUANTITY_FALLBACK_VOCABULARY). Empty disables the fallback and keeps the renderer inside the provided context.

required

Returns:

Name Type Description
str str

The guideline bullet for the configured fallback.

Source code in ontocast/prompt/facts_guidelines.py
def format_quantity_fallback_clause(vocabulary: dict[str, str]) -> str:
    """Render the bounded-quantity fallback for a configured vocabulary.

    The fallback is what the renderer reaches for when retrieval supplied no
    bounded-quantity class. Which vocabulary that is belongs to the deployment,
    not to the prompt: a catalog modelling quantities with anything other than
    QUDT would otherwise be told to emit QUDT terms it never declared.

    Args:
        vocabulary: Role -> term mapping (``FACTS_QUANTITY_FALLBACK_VOCABULARY``).
            Empty disables the fallback and keeps the renderer inside the
            provided context.

    Returns:
        str: The guideline bullet for the configured fallback.
    """
    if not vocabulary:
        return _QUANTITY_FALLBACK_NONE
    return _QUANTITY_FALLBACK_TEMPLATE.format(
        value_class=vocabulary.get("value_class", "a quantity-value class"),
        numeric_value=vocabulary.get("numeric_value", "its numeric-value property"),
        unit=vocabulary.get("unit", "its unit property"),
    )