% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/vlm-validate.R
\name{validate_or_retry}
\alias{validate_or_retry}
\title{Call a provider, validate JSON output, retry on failure}
\usage{
validate_or_retry(provider, prompt, schema, max_retries = 3L, image = NULL)
}
\arguments{
\item{provider}{An \code{ellmer} chat object (from
\code{\link{vlm_provider}}) or a \code{\link{MockVLMProvider}}
instance. Must expose a \code{$chat(prompt, ...)} method
returning text (or a character vector of length 1).}

\item{prompt}{Character scalar with the initial prompt.}

\item{schema}{Short schema name (\code{"horizon"}, \code{"site"}).}

\item{max_retries}{Integer; total attempts will be at most
\code{1 + max_retries}.}

\item{image}{Optional \code{ellmer} image content object (e.g.
from \code{ellmer::content_image_file}) to pass alongside
the prompt for multimodal calls.}
}
\value{
A list with elements \code{data} (parsed R object),
        \code{raw} (character scalar), \code{attempts} (integer).
}
\description{
Sends \code{prompt} to \code{provider}, parses the response as
JSON, and validates it against \code{schema} (a short schema name
resolved via \code{\link{load_schema}}). If validation fails, the
error message is appended to the prompt and the call is retried
up to \code{max_retries} times.
}
\details{
On success, returns a list with the parsed JSON, the raw text, and
the number of attempts taken. On terminal failure, throws.

This is the single place where the VLM-call -> validate -> retry
contract is implemented; every user-facing extractor delegates
here.
}
\keyword{internal}
