Unable to get deterministic structured JSON output for dynamic Azure ARM templates using OpenAIChatCompletionClient and response_format #6066
Unanswered
Shaik-Vaheed-UP
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am building an application that updates Azure ARM templates based on Azure Policy definitions. The challenge is that I need the LLM to return a deterministic structured JSON output every time, but the ARM template structure changes depending on the Azure resource type.
Although most ARM resources follow a common high-level structure such as id, name, type, kind, location, tags, properties, and sku, the internal fields inside objects like properties and sku vary by resource type. Because of that, I cannot define one fixed schema that fully covers all possible ARM resources.
class TobeAzureResourceResponse(BaseModel):
model_config = {"extra": "forbid"}
id: str = Field(description="The unique identifier of the Azure resource.")
name: str = Field(description="The name of the Azure resource.")
type: str = Field(description="The type of the Azure resource, e.g., Microsoft.Compute/virtualMachines.")
kind: str = Field(None, description="The kind of the Azure resource.")
location: str = Field(None, description="The location of the Azure resource.")
sku: str = Field(None, description="The SKU of the Azure resource.")
tags: str = Field(None, description="The tags associated with the Azure resource.")
properties: str = Field(None, description="The properties of the Azure resource.")
Issue
The main issues I am facing are:
Even after passing response_format, I am still receiving the model output as a string instead of a strongly structured JSON object.
Since the ARM template schema changes with resource type, I do not know how to define a schema that is both:
strict enough to enforce deterministic response format
flexible enough to support dynamic ARM resource structures
I am not sure whether response_format alone is the correct approach for this use case, or whether I should instead use:
a Pydantic schema
a JSON schema with strict mode
function/tool calling
or another pattern for dynamic structured outputs
I also want to understand the best practice for scenarios where only a partial high-level schema is known, but nested fields are dynamic.
Beta Was this translation helpful? Give feedback.
All reactions