Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

chore: move HIPAA checks from org to project level (#35925)

Etienne Stalmans8709747e9bfd
diff --git a/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx b/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
index b11aa92fa28..2f062081911 100644
--- a/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
@@ -11,6 +11,7 @@ import {
import { Snippet } from 'data/content/sql-folders-query'
import type { SqlSnippet } from 'data/content/sql-snippets-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
+import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'
import { createTabId, useTabsStateSnapshot } from 'state/tabs'
@@ -42,9 +43,10 @@ const RenameQueryModal = ({
)
const isSQLSnippet = snippet.type === 'sql'
const isSQLEditorTabsEnabled = useIsSQLEditorTabsEnabled()
+ const { data: projectSettings } = useProjectSettingsV2Query({ projectRef: ref })
// Customers on HIPAA plans should not have access to Supabase AI
- const hasHipaaAddon = subscriptionHasHipaaAddon(subscription)
+ const hasHipaaAddon = subscriptionHasHipaaAddon(subscription) && projectSettings?.is_sensitive
const { id, name, description } = snippet
diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
index bbb13eef394..4d86bfb86e1 100644
--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
@@ -17,10 +17,9 @@ import { constructHeaders, isValidConnString } from 'data/fetchers'
import { lintKeys } from 'data/lint/keys'
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
import { useExecuteSqlMutation } from 'data/sql/execute-sql-mutation'
-import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { isError } from 'data/utils/error-check'
-import { useOrgOptedIntoAi } from 'hooks/misc/useOrgOptedIntoAi'
+import { useOrgOptedIntoAiAndHippaProject } from 'hooks/misc/useOrgOptedIntoAi'
import { useSchemasForAi } from 'hooks/misc/useSchemasForAi'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
@@ -53,7 +52,6 @@ import {
cn,
} from 'ui'
import { useIsSQLEditorTabsEnabled } from '../App/FeaturePreview/FeaturePreviewContext'
-import { subscriptionHasHipaaAddon } from '../Billing/Subscription/Subscription.utils'
import { useSqlEditorDiff, useSqlEditorPrompt } from './hooks'
import { RunQueryWarningModal } from './RunQueryWarningModal'
import {
@@ -94,9 +92,9 @@ export const SQLEditor = () => {
const snapV2 = useSqlEditorV2StateSnapshot()
const getImpersonatedRoleState = useGetImpersonatedRoleState()
const databaseSelectorState = useDatabaseSelectorStateSnapshot()
- const isOptedInToAI = useOrgOptedIntoAi()
+ const { isOptedInToAI, isHipaaProjectDisallowed } = useOrgOptedIntoAiAndHippaProject()
const [selectedSchemas] = useSchemasForAi(project?.ref!)
- const includeSchemaMetadata = isOptedInToAI || !IS_PLATFORM
+ const includeSchemaMetadata = (isOptedInToAI && !isHipaaProjectDisallowed) || !IS_PLATFORM
const isSQLEditorTabsEnabled = useIsSQLEditorTabsEnabled()
const {
@@ -141,10 +139,6 @@ export const SQLEditor = () => {
useAddDefinitions(id, monacoRef.current)
- /** React query data fetching */
- const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: org?.slug })
- const hasHipaaAddon = subscriptionHasHipaaAddon(subscription)
-
const { data: databases, isSuccess: isSuccessReadReplicas } = useReadReplicasQuery(
{
projectRef: ref,
@@ -295,7 +289,7 @@ export const SQLEditor = () => {
return
}
- if (!hasHipaaAddon && snippet?.snippet.name === untitledSnippetTitle) {
+ if (!isHipaaProjectDisallowed && snippet?.snippet.name === untitledSnippetTitle) {
// Intentionally don't await title gen (lazy)
setAiTitle(id, sql)
}
@@ -340,7 +334,7 @@ export const SQLEditor = () => {
id,
isExecuting,
project,
- hasHipaaAddon,
+ isHipaaProjectDisallowed,
execute,
getImpersonatedRoleState,
setAiTitle,
diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
index 8df66345dda..2ba401c2127 100644
--- a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityTabResults.tsx
@@ -7,6 +7,7 @@ import { subscriptionHasHipaaAddon } from 'components/interfaces/Billing/Subscri
import CopyButton from 'components/ui/CopyButton'
import { InlineLink, InlineLinkClassName } from 'components/ui/InlineLink'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
+import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'
import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'
@@ -33,7 +34,8 @@ const UtilityTabResults = forwardRef<HTMLDivElement, UtilityTabResultsProps>(
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug })
// Customers on HIPAA plans should not have access to Supabase AI
- const hasHipaaAddon = subscriptionHasHipaaAddon(subscription)
+ const { data: projectSettings } = useProjectSettingsV2Query({ projectRef: ref })
+ const hasHipaaAddon = subscriptionHasHipaaAddon(subscription) && projectSettings?.is_sensitive
const isTimeout =
result?.error?.message?.includes('canceling statement due to statement timeout') ||
diff --git a/apps/studio/components/interfaces/SqlGenerator/SqlGeneratorImpl.tsx b/apps/studio/components/interfaces/SqlGenerator/SqlGeneratorImpl.tsx
index 2090607d0b8..d7a802c8a32 100644
--- a/apps/studio/components/interfaces/SqlGenerator/SqlGeneratorImpl.tsx
+++ b/apps/studio/components/interfaces/SqlGenerator/SqlGeneratorImpl.tsx
@@ -4,7 +4,7 @@ import { useEffectOnce } from 'react-use'
import { IS_PLATFORM } from 'common'
import { useEntityDefinitionsQuery } from 'data/database/entity-definitions-query'
-import { useOrgOptedIntoAi } from 'hooks/misc/useOrgOptedIntoAi'
+import { useOrgOptedIntoAiAndHippaProject } from 'hooks/misc/useOrgOptedIntoAi'
import { useSchemasForAi } from 'hooks/misc/useSchemasForAi'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { formatSql } from 'lib/formatSql'
@@ -45,11 +45,14 @@ import { SAMPLE_QUERIES, generatePrompt } from './SqlGenerator.utils'
import { SQLOutputActions } from './SqlOutputActions'
function useSchemaMetadataForAi() {
- const isOptedInToAI = useOrgOptedIntoAi()
+ const { isOptedInToAI, isHipaaProjectDisallowed } = useOrgOptedIntoAiAndHippaProject()
const project = useSelectedProject()
const [schemas] = useSchemasForAi(project?.ref!)
- const includeMetadata = (isOptedInToAI || !IS_PLATFORM) && schemas.length > 0 && !!project
+ const includeMetadata =
+ ((isOptedInToAI && !isHipaaProjectDisallowed) || !IS_PLATFORM) &&
+ schemas.length > 0 &&
+ !!project
const metadataSkipReason: AiMetadataSkipReason = !project ? 'no_project' : 'forbidden'
diff --git a/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx b/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx
index b1db254cf7f..1ebea56eb35 100644
--- a/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx
+++ b/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx
@@ -9,18 +9,16 @@ import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { toast } from 'sonner'
import { useParams, useSearchParamsShallow } from 'common/hooks'
-import { subscriptionHasHipaaAddon } from 'components/interfaces/Billing/Subscription/Subscription.utils'
import { Markdown } from 'components/interfaces/Markdown'
import OptInToOpenAIToggle from 'components/interfaces/Organization/GeneralSettings/OptInToOpenAIToggle'
import { SQL_TEMPLATES } from 'components/interfaces/SQLEditor/SQLEditor.queries'
import { useCheckOpenAIKeyQuery } from 'data/ai/check-api-key-query'
import { constructHeaders } from 'data/fetchers'
import { useOrganizationUpdateMutation } from 'data/organizations/organization-update-mutation'
-import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useTablesQuery } from 'data/tables/tables-query'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
-import { useOrgOptedIntoAi } from 'hooks/misc/useOrgOptedIntoAi'
+import { useOrgOptedIntoAiAndHippaProject } from 'hooks/misc/useOrgOptedIntoAi'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { useFlag } from 'hooks/ui/useFlag'
@@ -90,9 +88,9 @@ interface AIAssistantProps {
export const AIAssistant = ({ className }: AIAssistantProps) => {
const router = useRouter()
const project = useSelectedProject()
- const isOptedInToAI = useOrgOptedIntoAi()
+ const { isOptedInToAI, isHipaaProjectDisallowed } = useOrgOptedIntoAiAndHippaProject()
const selectedOrganization = useSelectedOrganization()
- const { id: entityId } = useParams()
+ const { ref, id: entityId } = useParams()
const searchParams = useSearchParamsShallow()
const includeSchemaMetadata = isOptedInToAI || !IS_PLATFORM
@@ -116,9 +114,6 @@ export const AIAssistant = ({ className }: AIAssistantProps) => {
const snippet = snippets[entityId ?? '']
const snippetContent = snippet?.snippet?.content?.sql
- const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: selectedOrganization?.slug })
- const hasHipaaAddon = subscriptionHasHipaaAddon(subscription)
-
const { data: tables, isLoading: isLoadingTables } = useTablesQuery(
{
projectRef: project?.ref,
@@ -132,8 +127,6 @@ export const AIAssistant = ({ className }: AIAssistantProps) => {
const currentSchema = searchParams?.get('schema') ?? 'public'
const currentChat = snap.activeChat?.name
- const { ref } = useParams()
- const org = useSelectedOrganization()
const { mutate: sendEvent } = useSendEventMutation()
const handleError = useCallback((error: Error) => {
@@ -238,12 +231,18 @@ export const AIAssistant = ({ className }: AIAssistantProps) => {
if (content.includes('Help me to debug')) {
sendEvent({
action: 'assistant_debug_submitted',
- groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
+ groups: {
+ project: ref ?? 'Unknown',
+ organization: selectedOrganization?.slug ?? 'Unknown',
+ },
})
} else {
sendEvent({
action: 'assistant_prompt_submitted',
- groups: { project: ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
+ groups: {
+ project: ref ?? 'Unknown',
+ organization: selectedOrganization?.slug ?? 'Unknown',
+ },
})
}
}
@@ -381,13 +380,13 @@ export const AIAssistant = ({ className }: AIAssistantProps) => {
type="default"
title="Project metadata is not shared"
description={
- hasHipaaAddon
- ? 'Your organization has the HIPAA addon and will not send any project metadata with your prompts.'
+ isHipaaProjectDisallowed
+ ? 'Your organization has the HIPAA addon and will not send project metadata with your prompts for projects marked as HIPAA.'
: 'The Assistant can improve the quality of the answers if you send project metadata along with your prompts. Opt into sending anonymous data to share your schema and table definitions.'
}
className="border-0 border-b rounded-none bg-background"
>
- {!hasHipaaAddon && (
+ {!isHipaaProjectDisallowed && (
<Button
type="default"
className="w-fit mt-4"
diff --git a/apps/studio/components/ui/AISettingsModal.tsx b/apps/studio/components/ui/AISettingsModal.tsx
index 2c1d1519882..c1393d3d614 100644
--- a/apps/studio/components/ui/AISettingsModal.tsx
+++ b/apps/studio/components/ui/AISettingsModal.tsx
@@ -1,6 +1,6 @@
import Link from 'next/link'
-import { useOrgOptedIntoAi } from 'hooks/misc/useOrgOptedIntoAi'
+import { useOrgOptedIntoAiAndHippaProject } from 'hooks/misc/useOrgOptedIntoAi'
import { useSchemasForAi } from 'hooks/misc/useSchemasForAi'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
@@ -19,12 +19,12 @@ import { SchemaComboBox } from './SchemaComboBox'
const AISettingsModal = () => {
const snap = useAppStateSnapshot()
const selectedOrganization = useSelectedOrganization()
- const isOptedInToAI = useOrgOptedIntoAi()
+ const { isOptedInToAI, isHipaaProjectDisallowed } = useOrgOptedIntoAiAndHippaProject()
const selectedProject = useSelectedProject()
const [selectedSchemas, setSelectedSchemas] = useSchemasForAi(selectedProject?.ref!)
- const includeSchemaMetadata = isOptedInToAI || !IS_PLATFORM
+ const includeSchemaMetadata = (isOptedInToAI && !isHipaaProjectDisallowed) || !IS_PLATFORM
return (
<Modal
@@ -45,7 +45,7 @@ const AISettingsModal = () => {
} selected`
: 'No schemas selected'
}
- disabled={IS_PLATFORM && !isOptedInToAI}
+ disabled={(IS_PLATFORM && !isOptedInToAI) || isHipaaProjectDisallowed}
selectedSchemas={selectedSchemas}
onSelectSchemas={setSelectedSchemas}
/>
@@ -54,16 +54,18 @@ const AISettingsModal = () => {
request. This will generate queries that are more relevant to your project.
</p>
</div>
- {IS_PLATFORM && !isOptedInToAI && selectedOrganization && (
+ {IS_PLATFORM && (!isOptedInToAI || isHipaaProjectDisallowed) && selectedOrganization && (
<Alert_Shadcn_ variant="warning">
<WarningIcon />
<AlertTitle_Shadcn_>
- Your organization does not allow sending anonymous data to OpenAI
+ {isHipaaProjectDisallowed
+ ? 'Sending data to OpenAI is disabled for HIPAA projects'
+ : 'Your organization does not allow sending anonymous data to OpenAI'}
</AlertTitle_Shadcn_>
<AlertDescription_Shadcn_>
This option is only available if your organization has opted-in to sending anonymous
- data to OpenAI. You may configure your opt-in preferences through your organization's
- settings.
+ data to OpenAI and non-HIPAA projects. You may configure your opt-in preferences
+ through your organization's settings.
</AlertDescription_Shadcn_>
<AlertDescription_Shadcn_ className="mt-3">
<Button asChild type="default">
diff --git a/apps/studio/components/ui/EditorPanel/EditorPanel.tsx b/apps/studio/components/ui/EditorPanel/EditorPanel.tsx
index d6b59203dd4..acfb5394781 100644
--- a/apps/studio/components/ui/EditorPanel/EditorPanel.tsx
+++ b/apps/studio/components/ui/EditorPanel/EditorPanel.tsx
@@ -12,7 +12,7 @@ import Results from 'components/interfaces/SQLEditor/UtilityPanel/Results'
import { SqlRunButton } from 'components/interfaces/SQLEditor/UtilityPanel/RunButton'
import { useSqlTitleGenerateMutation } from 'data/ai/sql-title-mutation'
import { QueryResponseError, useExecuteSqlMutation } from 'data/sql/execute-sql-mutation'
-import { useOrgOptedIntoAi } from 'hooks/misc/useOrgOptedIntoAi'
+import { useOrgOptedIntoAiAndHippaProject } from 'hooks/misc/useOrgOptedIntoAi'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { BASE_PATH, IS_PLATFORM } from 'lib/constants'
import { uuidv4 } from 'lib/helpers'
@@ -55,8 +55,8 @@ export const EditorPanel = ({ onChange }: EditorPanelProps) => {
const { profile } = useProfile()
const snapV2 = useSqlEditorV2StateSnapshot()
const { mutateAsync: generateSqlTitle } = useSqlTitleGenerateMutation()
- const isOptedInToAI = useOrgOptedIntoAi()
- const includeSchemaMetadata = isOptedInToAI || !IS_PLATFORM
+ const { isOptedInToAI, isHipaaProjectDisallowed } = useOrgOptedIntoAiAndHippaProject()
+ const includeSchemaMetadata = (isOptedInToAI && !isHipaaProjectDisallowed) || !IS_PLATFORM
const [isSaving, setIsSaving] = useState(false)
const [error, setError] = useState<QueryResponseError>()
diff --git a/apps/studio/hooks/misc/useDisallowHipaa.ts b/apps/studio/hooks/misc/useDisallowHipaa.ts
index 5958b82fb33..5c3cab91b62 100644
--- a/apps/studio/hooks/misc/useDisallowHipaa.ts
+++ b/apps/studio/hooks/misc/useDisallowHipaa.ts
@@ -1,19 +1,23 @@
import { useCallback } from 'react'
import { subscriptionHasHipaaAddon } from 'components/interfaces/Billing/Subscription/Subscription.utils'
+import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
+import { useSelectedProject } from 'hooks/misc/useSelectedProject'
export function useDisallowHipaa() {
const selectedOrganization = useSelectedOrganization()
+ const project = useSelectedProject()
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: selectedOrganization?.slug })
const hasHipaaAddon = subscriptionHasHipaaAddon(subscription)
+ const { data: projectSettings } = useProjectSettingsV2Query({ projectRef: project?.ref })
const disallowHipaa = useCallback(
(allowed: boolean) => {
- return hasHipaaAddon ? false : allowed
+ return hasHipaaAddon && projectSettings?.is_sensitive ? false : allowed
},
- [hasHipaaAddon]
+ [hasHipaaAddon, projectSettings]
)
return disallowHipaa
diff --git a/apps/studio/hooks/misc/useOrgOptedIntoAi.ts b/apps/studio/hooks/misc/useOrgOptedIntoAi.ts
index 7c1f3522254..54219afe9b0 100644
--- a/apps/studio/hooks/misc/useOrgOptedIntoAi.ts
+++ b/apps/studio/hooks/misc/useOrgOptedIntoAi.ts
@@ -1,4 +1,5 @@
import { useDisallowHipaa } from 'hooks/misc/useDisallowHipaa'
+import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { OPT_IN_TAGS } from 'lib/constants'
@@ -9,9 +10,26 @@ import { OPT_IN_TAGS } from 'lib/constants'
*/
export function useOrgOptedIntoAi() {
const selectedOrganization = useSelectedOrganization()
+ const selectedProject = useSelectedProject()
const optInTags = selectedOrganization?.opt_in_tags
const isOptedIntoAI = optInTags?.includes(OPT_IN_TAGS.AI_SQL) ?? false
const disallowHipaa = useDisallowHipaa()
- return disallowHipaa(isOptedIntoAI)
+ /* if we are in a project context and this has been called,
+ * ensure that we aren't letting HIPAA projects activate AI
+ * returns true if optedIntoAI and no project selected
+ * returns true if optedIntoAI and we are in a project and not HIPAA project
+ * returns false if opted out of AI
+ * returns false if optedIntoAI and we are in a HIPAA project
+ */
+ return isOptedIntoAI && (!selectedProject || disallowHipaa(isOptedIntoAI))
+}
+
+export function useOrgOptedIntoAiAndHippaProject() {
+ const selectedOrganization = useSelectedOrganization()
+ const optInTags = selectedOrganization?.opt_in_tags
+ const isOptedIntoAI = optInTags?.includes(OPT_IN_TAGS.AI_SQL) ?? false
+
+ const disallowHipaa = useDisallowHipaa()
+ return { isOptedInToAI: isOptedIntoAI, isHipaaProjectDisallowed: disallowHipaa(isOptedIntoAI) }
}
diff --git a/apps/studio/pages/project/[ref]/functions/[functionSlug]/code.tsx b/apps/studio/pages/project/[ref]/functions/[functionSlug]/code.tsx
index 4984b7009a2..fe6d8208855 100644
--- a/apps/studio/pages/project/[ref]/functions/[functionSlug]/code.tsx
+++ b/apps/studio/pages/project/[ref]/functions/[functionSlug]/code.tsx
@@ -15,7 +15,7 @@ import { useEdgeFunctionQuery } from 'data/edge-functions/edge-function-query'
import { useEdgeFunctionDeployMutation } from 'data/edge-functions/edge-functions-deploy-mutation'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
-import { useOrgOptedIntoAi } from 'hooks/misc/useOrgOptedIntoAi'
+import { useOrgOptedIntoAiAndHippaProject } from 'hooks/misc/useOrgOptedIntoAi'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { BASE_PATH, IS_PLATFORM } from 'lib/constants'
@@ -24,8 +24,8 @@ import { LogoLoader } from 'ui'
const CodePage = () => {
const { ref, functionSlug } = useParams()
const project = useSelectedProject()
- const isOptedInToAI = useOrgOptedIntoAi()
- const includeSchemaMetadata = isOptedInToAI || !IS_PLATFORM
+ const { isOptedInToAI, isHipaaProjectDisallowed } = useOrgOptedIntoAiAndHippaProject()
+ const includeSchemaMetadata = (isOptedInToAI && !isHipaaProjectDisallowed) || !IS_PLATFORM
const { mutate: sendEvent } = useSendEventMutation()
const org = useSelectedOrganization()
const [showDeployWarning, setShowDeployWarning] = useState(false)
diff --git a/apps/studio/pages/project/[ref]/functions/new.tsx b/apps/studio/pages/project/[ref]/functions/new.tsx
index 5a69bbe84e9..9e9c8848bb8 100644
--- a/apps/studio/pages/project/[ref]/functions/new.tsx
+++ b/apps/studio/pages/project/[ref]/functions/new.tsx
@@ -14,7 +14,7 @@ import { PageLayout } from 'components/layouts/PageLayout/PageLayout'
import FileExplorerAndEditor from 'components/ui/FileExplorerAndEditor/FileExplorerAndEditor'
import { useEdgeFunctionDeployMutation } from 'data/edge-functions/edge-functions-deploy-mutation'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
-import { useOrgOptedIntoAi } from 'hooks/misc/useOrgOptedIntoAi'
+import { useOrgOptedIntoAiAndHippaProject } from 'hooks/misc/useOrgOptedIntoAi'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { BASE_PATH, IS_PLATFORM } from 'lib/constants'
@@ -100,8 +100,8 @@ const NewFunctionPage = () => {
const router = useRouter()
const { ref, template } = useParams()
const project = useSelectedProject()
- const isOptedInToAI = useOrgOptedIntoAi()
- const includeSchemaMetadata = isOptedInToAI || !IS_PLATFORM
+ const { isOptedInToAI, isHipaaProjectDisallowed } = useOrgOptedIntoAiAndHippaProject()
+ const includeSchemaMetadata = (isOptedInToAI && !isHipaaProjectDisallowed) || !IS_PLATFORM
const snap = useAiAssistantStateSnapshot()
const { mutate: sendEvent } = useSendEventMutation()
const org = useSelectedOrganization()