Skip to content

Core spec: allow ai_context and custom_extensions on the document root - #323

Open
eisber wants to merge 1 commit into
apache:mainfrom
eisber:eisber/document-ai-context
Open

Core spec: allow ai_context and custom_extensions on the document root#323
eisber wants to merge 1 commit into
apache:mainfrom
eisber:eisber/document-ai-context

Conversation

@eisber

@eisber eisber commented Aug 12, 2026

Copy link
Copy Markdown

Summary

The document root is the only node in the core spec with no ai_context and no custom_extensions. Both keys appear on SemanticModel, Dataset, Field, Metric and Relationship; the root is closed (additionalProperties: false) with only version and semantic_model.

Since semantic_model is a list, guidance that governs every model in a document has nowhere to live. A producer emitting one model per data source must copy shared instructions into each model, and a consumer cannot tell those copies apart from genuinely model-specific instruction. See #322 for the full motivation.

This PR adds two optional keys to the document root:

Key Type
ai_context $ref: #/$defs/AIContext
custom_extensions array of #/$defs/CustomExtension

Semantics: document-level context applies to every semantic model in the document; model-level ai_context adds to it and takes precedence where the two conflict.

Precedent

This is not a new concept for the project. An ontology document already carries ai_context on its root, and $refs this spec's definition:

"ai_context": { "$ref": "../core-spec/osi-schema.json#/$defs/AIContext" }

The core spec already defines document-wide AI context — the core document root was simply the only root that never consumed it. A test pins both roots to the same AIContext definition so they cannot drift.

Not a breaking change

  • No new $defs — both keys reuse existing definitions.
  • required is unchanged; both keys are optional.
  • additionalProperties: false is unchanged, so the root stays closed. Unknown root keys, a wrong-typed ai_context, and an extension missing data are all still rejected.
  • examples/tpcds_semantic_model.yaml validates unchanged, and absent keys do not serialize.

Interaction with other open work

Related Issues

Refs #322

Checklist

Specification

Ontology

  • Ontology changes in ontology/ are consistent with spec changes — ontology/ is untouched; it already had root ai_context and this aligns core with it
  • New or modified terms are defined and documented

Converters

  • Converter logic in converters/ is updated to reflect spec or ontology changes — not applicable, both keys are optional and no converter emits them
  • New converters include tests under the converter's test directory — not applicable

Validation

  • Validation rules in validation/ are updated if the spec changed — validate.py is schema-driven and needed no change; verified positive, negative and back-compat cases against it
  • New validation cases are covered by tests

Documentation

  • docs/ is updated to reflect any user-facing changes
  • New features or behaviors are documented with examples where appropriate — new "Document" section in spec.md with a worked example
  • CONTRIBUTING.md is updated if the contribution process changed — not applicable

Examples

  • examples/ are added or updated for any new spec constructs — no example changes; the worked example lives in spec.md, and tpcds_semantic_model.yaml is intentionally left unchanged to demonstrate back-compat

Tests

  • All existing tests pass (pytest / CI green) — 9 -> 14 passing
  • New functionality is covered by tests — 5 new tests, including one pinning the core and ontology roots to the same AIContext definition

Compliance

  • ASF license headers are present on all new source files — no new files added
  • No third-party dependencies are added without PMC/IPMC approval — none added

The root object is the only node in the spec with no ai_context and no
custom_extensions: both appear on SemanticModel, Dataset, Field, Metric and
Relationship, but the document itself is closed (additionalProperties: false)
with only version and semantic_model.

A document holds a LIST of semantic models, so guidance that governs all of
them has nowhere to live. A producer emitting one model per data source must
copy shared instructions into every model so no model can be read without
them, and a consumer cannot tell those copies apart from genuinely
model-specific instruction.

Document-wide context is already an established shape in Ossie: an ontology
document carries ai_context on its root and $refs this specification's
AIContext definition. Core documents were the only root without it, so this
follows the existing precedent rather than introducing a new concept, and a
test pins the two roots to the same definition.

Both keys are optional and the root stays closed, so existing documents
validate unchanged.

Refs: apache#322
Copilot AI lite review requested due to automatic review settings August 12, 2026 20:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for document-scoped guidance and vendor metadata by allowing ai_context and custom_extensions on the core spec document root, aligning the core document root with patterns already used elsewhere (and with the ontology root).

Changes:

  • Extend core-spec/osi-schema.json document root with optional ai_context and custom_extensions (root remains closed).
  • Update the Python reference model and tests to parse/serialize ai_context / custom_extensions at the document level.
  • Update spec/docs to document the new document-level fields and their precedence semantics.
Show a summary per file
File Description
python/tests/test_models.py Adds regression tests asserting schema/root parity and round-trip serialization for document-level ai_context and custom_extensions.
python/src/ossie/models.py Adds ai_context and custom_extensions to the OSIDocument Pydantic model.
docs/index.md Updates docs text to include document-level AI context.
core-spec/spec.yaml Documents root-level ai_context / custom_extensions in the YAML spec summary.
core-spec/spec.md Adds a new “Document” section with a worked example and precedence semantics.
core-spec/osi-schema.json Adds the new optional root properties with descriptions; keeps additionalProperties: false.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 6/6 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment on lines 211 to +216
version: str = "0.2.0.dev0"
dialects: Optional[list[OSIDialect]] = None
vendors: Optional[list[OSIVendor]] = None
ai_context: Optional[OSIAIContext] = None
semantic_model: list[OSISemanticModel]
custom_extensions: Optional[list[OSICustomExtension]] = None
Comment thread core-spec/spec.yaml
Comment on lines +61 to +73
# Optional: Document-wide context for AI tools.
# Applies to every semantic model in this document. Model-level ai_context adds to
# it and takes precedence where the two conflict.
# Use this for guidance that governs the document as a whole — a model read in
# isolation would otherwise have to repeat it.
# Can be a simple string or a structured object with instructions,
# synonyms, examples, or vendor-specific keys.
ai_context:
instructions: string
synonyms:
- string
examples:
- string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants