Structured Output by Language¶
This tutorial turns free text into validated JSON with StructuredOutput. The
same schema is implemented in five published-package examples:
Each example validates title, summary, and tags before returning the model
output. Invalid output fails instead of returning malformed data.
Schema¶
{
"type": "object",
"required": ["title", "summary", "tags"],
"properties": {
"title": { "type": "string" },
"summary": { "type": "string" },
"tags": { "type": "array", "items": { "type": "string" } }
}
}
Run by Language¶
Python¶
cd language/python/examples/structured-output
python -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python summarize.py "Quarterly status: all checks green."
Deterministic test:
.venv/bin/python -m unittest test_summarize.py -v
TypeScript¶
cd language/typescript/examples/structured-output
npm install
npm start -- "Quarterly status: all checks green."
npm test
Java¶
cd language/java/examples/structured-output
mvn -q compile exec:java -Dexec.args="Quarterly status: all checks green."
mvn -q test
C¶
cd language/csharp/examples/structured-output
dotnet run -- "Quarterly status: all checks green."
dotnet run -- --test
Rust¶
cd language/rust/examples/structured-output
cargo run
The deterministic check validates a valid summary and rejects output that omits required fields.
Prototype Walkthrough: Python Structured-Output Processor¶
This is a complete first prototype for a primary SDK. It turns one free-text input into validated JSON and fails closed when the model omits required fields.
- Create an application directory and install the published package:
python -m venv .venv
.venv/bin/python -m pip install "praxo-core==0.8.0"
-
Copy the tested schema and agent setup from
language/python/examples/structured-output. Keep the explicit policy allowlist andStructuredOutputmiddleware. -
Run the deterministic model first:
.venv/bin/python summarize.py "Quarterly status: all checks green."
- Run the deterministic rejection test. A response missing
summaryortagsmust raise instead of returning partial JSON:
.venv/bin/python -m unittest test_summarize.py -v
-
Replace the fixture model with the OpenAI-compatible adapter only after the deterministic path passes. Keep the same schema and policy; do not remove the validation layer when moving to a real endpoint.
-
Record the package version, endpoint class, model name, schema version, and the command output. This is a local prototype, not a production service: identity, durable storage, retries, effect verification, and isolation remain application responsibilities.
The same pattern applies to the TypeScript, Java, C#, and Rust structured-output examples. A different language needs its own install command, executable example, and deterministic test before it counts as a complete path.
Prototype Walkthrough: TypeScript Structured-Output Processor¶
- Create an application directory and install the published package:
npm init -y
npm install --save-exact @axisvela/praxo-core@0.7.1
-
Copy the schema, fixture model, policy, and
StructuredOutputsetup fromlanguage/typescript/examples/structured-output. -
Run the deterministic prototype:
npm start -- "Quarterly status: all checks green."
npm test
-
The test must reject a response that omits
summaryortags; do not treat a parsed object as valid without schema validation. -
Replace the fixture model with
OpenAICompatibleModelonly after the deterministic test passes. Keep the same schema, allowlist, and policy. Record the package version, endpoint class, model name, and command output.
Prototype Walkthroughs: Java, C#, Rust, and R¶
Use the same schema and the tested example under each language's
examples/structured-output directory. The steps are the same: install the
published package, run the deterministic model, run the rejection test, then
switch to a real endpoint without removing validation.
Java
cd language/java/examples/structured-output
mvn -q compile exec:java -Dexec.args="Quarterly status: all checks green."
mvn -q test
C#
cd language/csharp/examples/structured-output
dotnet run -- "Quarterly status: all checks green."
dotnet run -- --test
Rust
cd language/rust/examples/structured-output
cargo run
Run the crate's tests in the same directory before replacing the fixture model.
The published praxo-core==0.9.1 crate uses the current adapter seams.
R
Rscript language/r/examples/structured-output/structured_output.R
Rscript language/r/tests/run_tests.R
For R, install praxocore from r-universe and keep the schema check in the
application. A successful parse without schema validation is not a passing
prototype.
Prototype Walkthroughs: Ruby, PHP, Elixir, and Lua¶
These extended-language Cores use the same schema and validation rule. Run the tested example first; it is a complete local prototype for that language.
Ruby
ruby -I language/ruby/lib language/ruby/examples/structured-output/structured_output.rb
PHP
php language/php/examples/structured-output/structured_output.php
Elixir
elixir -pa language/elixir/build/ebin language/elixir/examples/structured-output/structured_output.exs
Lua
lua language/lua/examples/structured-output/structured_output.lua
For each, confirm that invalid output is rejected before replacing the fixture model. These examples are source-mode prototypes; package installation and version pins remain language-specific.
For every language, record the package version, endpoint class, model name, schema version, commands, and output. Keep identity, durable storage, retries, effect verification, and isolation in the application.
Live Endpoint¶
The runnable commands use an OpenAI-compatible endpoint:
export PRAXO_BASE_URL=http://localhost:11434/v1
export PRAXO_MODEL=llama3.2
# export PRAXO_API_KEY=... # hosted endpoints only
On PowerShell:
$env:PRAXO_BASE_URL = "http://localhost:11434/v1"
$env:PRAXO_MODEL = "llama3.2"
What the Examples Prove¶
- the package is installed from a registry;
- the model adapter is configured from environment variables;
StructuredOutputvalidates the final JSON against the schema;- a fake-model test verifies the integration without a live endpoint.
They do not prove model quality, schema completeness, provider structured-output support, or production behavior. Keep the final schema validation in the application even when a provider supports structured output natively.