BoundaryML/baml · error · JsonishError

No JSON objects found

Error message

No JSON objects found

What it means

`JsonishError::NoJsonObjectsFound` is returned when the jsonish extractor scans the input text and finds no JSON object it can extract. The parser attempts to locate JSON within free-form LLM output, and if nothing resembling a JSON object is present, this variant is thrown.

Source

Thrown at baml_language/crates/bex_sap/src/jsonish/mod.rs:17

//! This module implements parsing JSON-like data into a structured representation.
//!
//! The main entry point is the [`parse`] function, which takes a string and returns a [`Value`].
//! This is basically the jsonish equivalent of [`serde_json::from_str`] and [`serde_json::Value`].

mod parser;
mod value;

pub use parser::{ParseOptions, parse};
pub use value::{CompletionState, Fixes, Value};

/// Error type for jsonish parsing failures.
#[derive(Debug, thiserror::Error)]
pub enum JsonishError {
    #[error("Depth limit reached. Likely a circular reference.")]
    DepthLimitReached,
    #[error("No JSON objects found")]
    NoJsonObjectsFound,
    #[error("No markdown blocks found")]
    NoMarkdownBlocksFound,
    #[error("Mismatched brackets")]
    MismatchedBrackets,
    #[error("No collection to consume token: {0:?}")]
    NoCollectionForToken(char),
    #[error("Failed to parse JSON")]
    ParseFailed,
}

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Log the raw input and confirm the model actually produced JSON; fix the prompt to require JSON output.
  2. Check you are parsing the correct response field (content vs. reasoning vs. tool output).
  3. Add a fallback: retry the request or use a repair prompt asking the model to emit valid JSON.
  4. Verify truncation settings (max tokens) aren't cutting the JSON off before it starts.

Example fix

// before
let v = jsonish::parse(response.text, &opts)?;
// after
let v = match jsonish::parse(&response.text, &opts) {
    Ok(v) => v,
    Err(JsonishError::NoJsonObjectsFound) => retry_with_json_repair_prompt(&response.text)?,
    Err(e) => return Err(e.into()),
};
Defensive patterns

Strategy: fallback

Validate before calling

if !raw.contains('{') && !raw.contains('[') {
    return Err("model produced no JSON at all; retry with stricter prompt");
}

Try / catch

match jsonish::parse(&raw, &opts) {
    Ok(v) => Ok(v),
    Err(JsonishError::NoJsonObjectsFound) => retry_with_json_repair_prompt(&raw),
    Err(e) => Err(e.into()),
}

Prevention

When it happens

Trigger: Calling `bex_sap::jsonish::parse` on text that contains no `{`...`}` (or extractable JSON) content at all — e.g. the model replied with plain prose or an apology instead of JSON.

Common situations: Model refuses the task and returns natural language; the prompt never asked for JSON output; output was truncated before any JSON appeared; wrong field of the response is being parsed.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/8d41e5c5fda8a5bd. Report an issue: GitHub.