Skip to main content

Module chart_spec_generation

Module chart_spec_generation 

Source

Structs§

ChartSpecGenerationInput
Input payload for chart spec generation.
DataFile
The data file a chart reads, as the request named it.

Constants§

DATA_SAMPLE_HEADING
Introduces the sample of the teacher’s data file. Also how the test-mode mock Azure API finds the sample, which it needs to answer with the field names the teacher’s file actually has.
EXISTING_SPEC_HEADING
Introduces the specification being edited, and so also ends DATA_SAMPLE_HEADING’s section.
MAX_GENERATION_ATTEMPTS 🔒
How many validation attempts the model gets in total (first answer + repair rounds).
MAX_REPORTED_VALIDATION_ERRORS 🔒
Caps for how much validation detail is echoed back to the model and the teacher; union schemas like Vega-Lite’s can produce very many, very long errors.
MAX_UNION_DEPTH 🔒
How many levels of union to follow when explaining why a specification was rejected.
MAX_VALIDATION_ERROR_CHARS 🔒
PLACEHOLDER_DATA_FILE 🔒
Stands in for the teacher’s file while a spec that has none is validated. The Vega-Lite schema requires a data source on a top-level view, so a chart still waiting for its file could not be checked at all otherwise. Never leaves parse_and_validate_spec.
SYSTEM_PROMPT 🔒
System prompt for generating a Vega-Lite chart specification for the CMS chart block.
USER_PROMPT_PREFIX
User prompt prefix. Also how the test-mode mock Azure API recognises a request from this feature, since a JSON-mode request carries no schema name to identify it by.

Statics§

VEGA_LITE_SCHEMA_JSON 🔒
Vendored copy of https://vega.github.io/schema/vega-lite/v6.json, used to validate generated specs without network access. All of its $refs are internal.

Functions§

attach_data_file 🔒
Points the spec at the data file the request named.
describe_validation_error 🔒
Describes a validation failure in terms a model can act on, into out.
find_data_source 🔒
Names the first data source anywhere in the spec, or None when it carries none.
generate_chart_spec
Generate a Vega-Lite chart specification from a teacher’s prompt using an LLM with structured JSON output. The result is validated against the Vega-Lite v6 JSON Schema; on failure the validation errors are sent back to the model for one repair round. Returns the specification pretty-printed as a JSON string.
parse_and_validate_spec 🔒
Parses one LLM answer, rejects any data the model supplied, attaches data_file and validates the result against the Vega-Lite schema. The error string describes the failure in a form suitable for feeding back to the model.
remove_data_sources 🔒
response_format 🔒
The format the chart spec LLM is asked to answer in.
sanitize_refs 🔒
Percent-encodes every $ref string in the schema.
text_message 🔒
union_branches 🔒
The branch errors of a union keyword, if this failure is one.
vega_lite_validator 🔒
The Vega-Lite validator built from the vendored schema; built once per process.
without_data 🔒
The spec with every data source taken out, or None when it isn’t parseable JSON.