LlmCore.Structured.JsonMode (llm_core v0.3.0)

Copy Markdown View Source

Helpers for working with providers that support JSON-mode outputs.

The helpers exposed here are intentionally lightweight so they can be used from providers, pipelines, and tests without introducing new dependencies.

Summary

Functions

Decodes the response content into a map/list.

Ensures the options passed to a provider request include JSON formatting.

Types

decoded()

@type decoded() :: map() | list()

Functions

decode(content)

@spec decode(LlmCore.LLM.Response.t() | binary() | decoded()) ::
  {:ok, decoded()} | {:error, term()}

Decodes the response content into a map/list.

When the content is already a map or list (for example, the provider returns parsed JSON), it is returned as-is.

enforce(opts)

@spec enforce(keyword()) :: keyword()

Ensures the options passed to a provider request include JSON formatting.

Providers that already set :format or :response_format are left untouched.