Runtime ModulesTransformation

JSON Normalizer

Extract, parse, and optionally validate JSON output from LLM responses before it continues through the pipeline.

JSON Normalizer ensures that LLM JSON outputs are clean, parseable, and optionally schema-conformant before they reach your application. It handles the common real-world issues with LLM JSON output: markdown code fences, surrounding prose, inconsistent whitespace, and structural deviations.

All extraction behaviors are always active — the module always strips fences, extracts JSON from prose, and parses the result. Schema validation is optional.


Stage

StageBehavior
POST onlyProcesses the LLM response: removes code fences, extracts JSON, parses it, and optionally validates it against a configured schema

What It Does

The module applies the following steps to every LLM response, in order:

  1. Fence removal: Strips ```json / ``` Markdown code fences if present.
  2. JSON extraction: Finds and extracts the first valid JSON object {} or array [] from the surrounding text, even if the LLM added explanatory prose before or after.
  3. Parsing: Parses the extracted string to confirm it is valid JSON.
  4. Schema validation (optional): If a JSON Schema is configured, the parsed object is validated against it. If validation fails, the pipeline raises an exception immediately.

Example

Raw LLM response:

Sure! Here is the result:

```json
{
  "status": "success",
  "items": ["apple", "banana"],
  "count": 2
}

Let me know if you need anything else!


**After normalization:**
```json
{"status": "success", "items": ["apple", "banana"], "count": 2}

Configuration

Expected Output Schema

A JSON Schema used to validate the extracted JSON output. You can build the schema visually in the Infralo UI by pasting an example JSON response — field types and required constraints are inferred automatically and can be adjusted.

Leave empty to skip schema validation and use this module purely for extraction and parsing.

Allow Additional Properties

Controls whether the LLM response may include fields not declared in the schema.

SettingBehavior
Disabled (default)Any extra field not in the schema causes validation to fail immediately
EnabledExtra fields are passed through as-is; only schema-declared fields are validated

Has no effect without a schema

The "Allow Additional Properties" setting only applies when a JSON Schema is configured. If the schema is empty, all fields pass through regardless of this setting.


Failure Behavior

If the extracted JSON does not match the configured schema and Allow Additional Properties is disabled, the module raises a pipeline exception immediately. It does not:

  • Retry the LLM call
  • Attempt to repair the JSON
  • Fall back to the raw response

This is intentional — it ensures that your downstream application never receives malformed or non-conformant data silently. Handle this at the application level by catching gateway errors and retrying if needed.


Example Use Cases

  • Structured output APIs: Ensure every LLM call that is expected to return JSON actually does so — gate on it at the infrastructure level.
  • Schema enforcement: Validate that required fields are present and correctly typed before the response reaches your database or downstream service.
  • Fence stripping: Many LLMs wrap JSON in markdown code fences by default; this module removes them reliably without any prompt engineering.
  • Prose cleanup: When using few-shot prompting that sometimes generates explanatory text around JSON, this module extracts only the JSON automatically.

Strict mode by default

With a schema configured and Additional Properties disabled (default), any undeclared field in the LLM response will fail validation. If your LLM frequently returns extra metadata fields, either add them to your schema or enable Additional Properties.

On this page