Skip to content

Commit c655abc

Browse files
authored
Merge pull request #967 from alphagov/follow-up-changes-to-llm-resposnes-and-metrics-default-change
[CHAT-417]Backfill llm_responses and metrics nil values and make columns non-nullable
2 parents 71f3daa + 5a9fdc4 commit c655abc

3 files changed

Lines changed: 59 additions & 13 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class BackfillNilvaluesForLlmResponsesAndMetrics < ActiveRecord::Migration[8.0]
2+
class AnswerAnalysisAnswerRelevancyRun < ApplicationRecord; end
3+
class AnswerAnalysisCoherenceRun < ApplicationRecord; end
4+
class AnswerAnalysisContextRelevancyRun < ApplicationRecord; end
5+
class AnswerAnalysisFaithfulnessRun < ApplicationRecord; end
6+
class AnswerAnalysisTopics < ApplicationRecord; end
7+
8+
MODELS = [
9+
AnswerAnalysisAnswerRelevancyRun,
10+
AnswerAnalysisCoherenceRun,
11+
AnswerAnalysisContextRelevancyRun,
12+
AnswerAnalysisFaithfulnessRun,
13+
AnswerAnalysisTopics,
14+
Answer,
15+
].freeze
16+
17+
def up
18+
MODELS.each do |model|
19+
model.where(metrics: nil).update_all(metrics: {})
20+
model.where(llm_responses: nil).update_all(llm_responses: {})
21+
end
22+
end
23+
24+
def down
25+
raise ActiveRecord::IrreversibleMigration
26+
end
27+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class MakeLlmResponsesAndMetricsNonNullable < ActiveRecord::Migration[8.0]
2+
TABLES = %i[
3+
answers
4+
answer_analysis_answer_relevancy_runs
5+
answer_analysis_coherence_runs
6+
answer_analysis_context_relevancy_runs
7+
answer_analysis_faithfulness_runs
8+
answer_analysis_topics
9+
].freeze
10+
11+
def change
12+
TABLES.each do |table|
13+
change_table table, bulk: true do |t|
14+
t.change_null :metrics, false
15+
t.change_null :llm_responses, false
16+
end
17+
end
18+
end
19+
end

db/schema.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.0].define(version: 2026_03_24_105142) do
13+
ActiveRecord::Schema[8.0].define(version: 2026_03_26_123210) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "citext"
1616
enable_extension "pg_catalog.plpgsql"
@@ -29,8 +29,8 @@
2929
create_table "answer_analysis_answer_relevancy_runs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
3030
t.decimal "score"
3131
t.string "reason"
32-
t.jsonb "llm_responses", default: {}
33-
t.jsonb "metrics", default: {}
32+
t.jsonb "llm_responses", default: {}, null: false
33+
t.jsonb "metrics", default: {}, null: false
3434
t.uuid "answer_id", null: false
3535
t.datetime "created_at", null: false
3636
t.datetime "updated_at", null: false
@@ -42,8 +42,8 @@
4242
create_table "answer_analysis_coherence_runs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
4343
t.decimal "score"
4444
t.string "reason"
45-
t.jsonb "llm_responses", default: {}
46-
t.jsonb "metrics", default: {}
45+
t.jsonb "llm_responses", default: {}, null: false
46+
t.jsonb "metrics", default: {}, null: false
4747
t.uuid "answer_id", null: false
4848
t.datetime "created_at", null: false
4949
t.datetime "updated_at", null: false
@@ -55,8 +55,8 @@
5555
create_table "answer_analysis_context_relevancy_runs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
5656
t.decimal "score"
5757
t.string "reason"
58-
t.jsonb "llm_responses", default: {}
59-
t.jsonb "metrics", default: {}
58+
t.jsonb "llm_responses", default: {}, null: false
59+
t.jsonb "metrics", default: {}, null: false
6060
t.uuid "answer_id", null: false
6161
t.datetime "created_at", null: false
6262
t.datetime "updated_at", null: false
@@ -68,8 +68,8 @@
6868
create_table "answer_analysis_faithfulness_runs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
6969
t.decimal "score"
7070
t.string "reason"
71-
t.jsonb "llm_responses", default: {}
72-
t.jsonb "metrics", default: {}
71+
t.jsonb "llm_responses", default: {}, null: false
72+
t.jsonb "metrics", default: {}, null: false
7373
t.uuid "answer_id", null: false
7474
t.datetime "created_at", null: false
7575
t.datetime "updated_at", null: false
@@ -81,8 +81,8 @@
8181
create_table "answer_analysis_topics", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
8282
t.string "primary_topic"
8383
t.string "secondary_topic"
84-
t.jsonb "metrics", default: {}
85-
t.jsonb "llm_responses", default: {}
84+
t.jsonb "metrics", default: {}, null: false
85+
t.jsonb "llm_responses", default: {}, null: false
8686
t.uuid "answer_id", null: false
8787
t.datetime "created_at", null: false
8888
t.datetime "updated_at", null: false
@@ -146,8 +146,8 @@
146146
t.string "answer_guardrails_failures", default: [], array: true
147147
t.enum "question_routing_label", enum_type: "question_routing_label"
148148
t.float "question_routing_confidence_score"
149-
t.jsonb "metrics", default: {}
150-
t.jsonb "llm_responses", default: {}
149+
t.jsonb "metrics", default: {}, null: false
150+
t.jsonb "llm_responses", default: {}, null: false
151151
t.enum "jailbreak_guardrails_status", enum_type: "guardrails_status"
152152
t.enum "question_routing_guardrails_status", enum_type: "guardrails_status"
153153
t.string "question_routing_guardrails_failures", default: [], array: true

0 commit comments

Comments
 (0)