Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated guardrails
  • Loading branch information
waleedlatif1 committed Feb 6, 2026
commit 209d2e0ca42e59658156d9da79265792613a1af3
1 change: 1 addition & 0 deletions apps/sim/app/api/copilot/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export async function POST(req: NextRequest) {
provider: 'azure-anthropic',
model: envModel,
apiKey: env.AZURE_ANTHROPIC_API_KEY,
apiVersion: env.AZURE_ANTHROPIC_API_VERSION,
endpoint: env.AZURE_ANTHROPIC_ENDPOINT,
}
} else if (providerEnv === 'vertex') {
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/blocks/blocks/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ Return ONLY the JSON array.`,
id: 'azureApiVersion',
title: 'Azure API Version',
type: 'short-input',
placeholder: '2024-07-01-preview',
placeholder: 'Enter API version',
connectionDroppable: false,
condition: {
field: 'model',
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/blocks/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export function getProviderCredentialSubBlocks(): SubBlockConfig[] {
id: 'azureApiVersion',
title: 'Azure API Version',
type: 'short-input',
placeholder: '2024-07-01-preview',
placeholder: 'Enter API version',
connectionDroppable: false,
condition: {
field: 'model',
Expand Down
1 change: 1 addition & 0 deletions apps/sim/lib/copilot/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export type CopilotProviderConfig =
provider: 'azure-anthropic'
model: string
apiKey?: string
apiVersion?: string
endpoint?: string
}
| {
Expand Down
1 change: 1 addition & 0 deletions apps/sim/lib/core/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const env = createEnv({
AZURE_OPENAI_API_KEY: z.string().min(1).optional(), // Shared Azure OpenAI API key
AZURE_ANTHROPIC_ENDPOINT: z.string().url().optional(), // Azure Anthropic service endpoint
AZURE_ANTHROPIC_API_KEY: z.string().min(1).optional(), // Azure Anthropic API key
AZURE_ANTHROPIC_API_VERSION: z.string().min(1).optional(), // Azure Anthropic API version (e.g. 2023-06-01)
KB_OPENAI_MODEL_NAME: z.string().optional(), // Knowledge base OpenAI model name (works with both regular OpenAI and Azure OpenAI)
WAND_OPENAI_MODEL_NAME: z.string().optional(), // Wand generation OpenAI model name (works with both regular OpenAI and Azure OpenAI)
OCR_AZURE_ENDPOINT: z.string().url().optional(), // Azure Mistral OCR service endpoint
Expand Down
28 changes: 26 additions & 2 deletions apps/sim/lib/guardrails/validate_hallucination.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { db } from '@sim/db'
import { account } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { eq } from 'drizzle-orm'
import { getBaseUrl } from '@/lib/core/utils/urls'
import { refreshTokenIfNeeded } from '@/app/api/auth/oauth/utils'
import { executeProviderRequest } from '@/providers'
import { getApiKey, getProviderFromModel } from '@/providers/utils'

Expand Down Expand Up @@ -138,6 +142,26 @@ Evaluate the consistency and provide your score and reasoning in JSON format.`

const providerId = getProviderFromModel(model)

// Resolve Vertex AI OAuth credential to access token if needed
let resolvedApiKey = apiKey
const resolvedCredentials = { ...providerCredentials }
if (providerId === 'vertex' && providerCredentials?.vertexCredential) {
const credential = await db.query.account.findFirst({
where: eq(account.id, providerCredentials.vertexCredential),
})
if (credential) {
const { accessToken } = await refreshTokenIfNeeded(
requestId,
credential,
providerCredentials.vertexCredential
)
if (accessToken) {
resolvedApiKey = accessToken
}
}
resolvedCredentials.vertexCredential = undefined
}

const response = await executeProviderRequest(providerId, {
model,
systemPrompt,
Expand All @@ -148,8 +172,8 @@ Evaluate the consistency and provide your score and reasoning in JSON format.`
},
],
temperature: 0.1, // Low temperature for consistent scoring
apiKey,
...providerCredentials,
apiKey: resolvedApiKey,
...resolvedCredentials,
})

if (response instanceof ReadableStream || ('stream' in response && 'execution' in response)) {
Expand Down