Azure AI Foundry Agent: Unable to Reassign a Guardrail from the Foundry UI

Riyazur Razak 0 Reputation points
2026-07-21T06:40:14.2+00:00

I'm encountering an issue when attempting to reassign a guardrail to an existing Azure AI Foundry hosted agent through the Foundry portal.
Steps to reproduce:

  1. Open the Azure AI Foundry portal.
  2. Navigate to Agent -> Playground -> Setup -> Guardrail.
  3. Select a different (or existing) guardrail and save the changes.

Expected behavior: The selected guardrail should be successfully assigned to the agent.

Actual behavior: The operation fails with a 400 Bad Request. The request appears to be sent with an application/json payload, whereas the service expects multipart/form-data because the agent has a code_configuration.

Error Response

{
    "error": {
        "code": "invalid_payload",
        "message": "code_configuration is not supported with application/json. Use multipart/form-data instead. [Request ID: <REDACTED>]",
        "param": "definition.code_configuration",
        "type": "invalid_request_error",
        "details": [],
        "additionalInfo": {
            "request_id": "<REDACTED>"
        }
    }
}

This appears to be an issue with the Foundry portal generating an incorrect request payload when updating the guardrail for a hosted code agent.

Has anyone encountered this issue, or is this a known limitation or bug in the Azure AI Foundry portal?

Foundry Agent Service
Foundry Agent Service

A fully managed platform in Microsoft Foundry for hosting, scaling, and securing AI agents built with any supported framework or model


2 answers

Sort by: Oldest
  1. Deepanshu katara 18,230 Reputation points MVP Volunteer Moderator
    2026-07-21T06:56:23.8266667+00:00

    Hello Riyazur,

    Welcome to MS Q&A

    This looks like a portal issue rather than a Content Safety/guardrail limitation. The error indicates the portal is sending the update as application/json, while hosted agents with a code_configuration require multipart/form-data:

    As a workaround, try updating the agent using the REST API or SDK. If that succeeds while the portal fails, it strongly suggests a bug in the Azure AI Foundry portal. Consider opening a support ticket with the Request ID and a network trace.

    References:

    Pls check and let me know if any questions

    Thanks

    Deepanshu

    Was this answer helpful?


  2. Manish Deshpande 8,135 Reputation points Microsoft External Staff Moderator
    2026-08-05T03:41:00.95+00:00

    Hello @Riyazur Razak

    Microsoft Foundry actually has two separate paths for creating/updating a Hosted agent's definition:

    1. The standard Agents REST API (POST /agents/{name} and POST /agents/{name}/versions) — this is JSON-only. Its request body content type is application/json, and guardrail assignment goes through a rai_config.rai_policy_name property on the agent's definition. This path is used for prompt agents, workflow agents, and image/container-based hosted agents.
    2. The source-code deployment path — used specifically for agents deployed from a .zip of code (which is what gives your agent its code_configuration). Because this call has to carry both the code archive and the agent metadata, it's sent as a multipart request rather than plain JSON.

    Since your agent was originally deployed from source code, its persisted definition includes code_configuration — and that field only exists on the multipart, code-deployment path, not on the plain-JSON update-agent path. When the Foundry portal's Setup → Guardrail → Save action tries to persist your guardrail selection, it looks like it's calling the generic JSON update endpoint — which has no way to carry code_configuration forward — so the service correctly rejects it rather than silently dropping your code configuration. That's exactly what the error is telling you: it's not that your payload is malformed, it's that the portal picked the wrong endpoint for this agent type.

    This also lines up with where things stand generally: guardrail assignment on newer Foundry constructs like Toolboxes is explicitly called out as not yet available through the portal/VS Code UI — the guidance there is to use the REST API or SDK instead. Source-code Hosted agents are still in preview with their own beta API surface, so it's very plausible the portal's Guardrail tab simply hasn't been wired up to route through the code-specific endpoint yet for this agent type.

    Workaround: reassign the guardrail via API instead of the portal You can set the guardrail directly by creating a new agent version through the source-code deployment path — re-supplying your existing code zip (unchanged) alongside the updated guardrail reference in the definition:

    content = CreateAgentVersionFromCodeContent(
        metadata=CreateAgentVersionFromCodeMetadata(
            definition=HostedAgentDefinition(
                cpu="1",
                memory="2Gi",
                code_configuration=CodeConfiguration(
                    runtime="python_3_13",
                    entry_point=["python", "main.py"],
                    dependency_resolution="remote_build",
                ),
                rai_config=RaiConfig(rai_policy_name="<your-guardrail-name>"),
                protocol_versions=[ProtocolVersionRecord(protocol="responses", version="1.0.0")],
            ),
        ),
        code=(ZIP_PATH.name, code_zip_bytes, "application/zip"),
    )
    
    project.beta.agents.create_version_from_code(
        agent_name=AGENT_NAME, content=content, code_zip_sha256=code_zip_sha256,
    )
    
    
    
    

    Same code, same runtime settings the only change is rai_config.rai_policy_name. This creates a new version with the guardrail correctly attached, entirely bypassing the portal's Save action. If you're doing this over raw REST rather than the SDK, remember to include the preview feature header on the call: Foundry-Features: CodeAgents=V1Preview,HostedAgents=V1Preview

    Thanks,
    Manish.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.